- #1
Eclair_de_XII
- 1,083
- 91
Homework Statement
"Using the time module, write a program that tells one the current time in hours, minutes, and seconds, and time since January the first of 1970."
Homework Equations
import time
% = mod division
int = returns integer value of number
The Attempt at a Solution
Python:
import time
now = int(time.time())
second = 1
minute = 60*second
hour = 60*minute
day = 24*hour
year=365.25*day
d = now%year
h = d%day # error here?
m = h%hour
s = m%minute
day_count = int(d/24/3600)
hour_count = int(h/3600)
min_count = int(m/60)
sec_count = int(s)
days_since_epoch = int(now/3600/24)
print("The current time is ",hour_count," hours, ",min_count," minutes, and ",sec_count," seconds.","It has been ",
days_since_epoch," days since the epoch.")
I have the minutes and seconds down correctly, but when I execute this program, it gives me the wrong hour. I know it hasn't anything to do with Python thinking I'm in some other timezone, because when I tried to calculate the time directly, it gave me the correct hour. So I'm thinking I messed up on the bolded text <Moderator's note: comment added instead> above. I don't quite know how to fix this...
*Oops, I noticed that I should have erased that "finding" in the title of this topic...
<Moderator's note: title fixed.>
Last edited by a moderator: