0

Seconds since epoch should be zero, but are not:

'''timetuple1.py
create a time tuple for epoch 1/1/1970 00:00:00
however, seconds since epoch does not give 0
'''

import time

timetuple = time.strptime("01/01/1970 00:00:00", "%m/%d/%Y %H:%M:%S")

print(timetuple)

print('-'*40)

# seconds since epoch 1/1/1970 00:00:00 
secs = time.mktime(timetuple)
print(secs)

'''my result >>
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=-1)
----------------------------------------
28800.0
'''

Does anybody know why it isn't zero?

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by HiHe
1

The epoch is OS dependent and has nothing to do with Python. Since we don't know what OS you are using the question can not be answered except to say print gmtime(0) and see what it tells you. 28800 seconds is something like 8 hours so it may be the difference between Greenwich time and local time.

Edited by woooee

0

Thanks woooee!
On Windows epoch is referenced as a local value (in my case LA time):

import time

local = time.localtime(0)
gmt   = time.gmtime(0)
print('time.localtime(0) =')
print(local)
print('-'*50)
print('time.gmtime(0) =')
print(gmt)

print('<>'*20)

print('time.mktime(local) =')
print(time.mktime(local))
print('-'*20)
print('time.mktime(gmt) =')
print(time.mktime(gmt))


'''my result -->
time.localtime(0) =
time.struct_time(tm_year=1969, tm_mon=12, tm_mday=31, tm_hour=16, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=365, tm_isdst=0)
--------------------------------------------------
time.gmtime(0) =
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)
<><><><><><><><><><><><><><><><><><><><>
time.mktime(local) =
0.0
--------------------
time.mktime(gmt) =
28800.0
'''
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.