3
I need to convert the passage of time from another planet to days, hours, minutes and seconds on earth.
The point is, I’m getting one int
(variable seg
) for the seconds spent on Jupiter and I need to know how much time is spent on Earth.
dia = (seg / 35760);
hora = (seg / 3600) - (dia * 24);
minuto = (seg % 3600) / 60;
segundo = (seg % 60);
35760 represents the number of seconds a day on Jupiter. (9 hours 56 minutes)
The entrance is: 267547464242
.
Expected output is: 7481752 days, 3 hours, 32 minutes and 2 seconds.
But the output that my code is presenting is:
7481752 days, -105243308 hours, 4 minutes, 2 seconds.
I made the same logic for other planets, and it worked, just the one that doesn’t work.
Can someone help me?
I think you will need to take the rest of the division, which is what is left, to calculate the other ``periods (rest of the day calculates hour, rest of the hour, calculates minute, etc). The rest operator in the
javascript
is percentage%
. For example267547464242 % 35760
will give 12722, or if that is what is left of the division of days, which are the hours– Ricardo Pontual