epoch

Convert python datetime to epoch with strftime

Convert python datetime to epoch with strftime Question: I have a time in UTC from which I want the number of seconds since epoch. I am using strftime to convert it to the number of seconds. Taking 1st April 2012 as an example. >>>datetime.datetime(2012,04,01,0,0).strftime(‘%s’) ‘1333234800’ 1st of April 2012 UTC from epoch is 1333238400 but …

Total answers: 8

Is a day always 86,400 epoch seconds long?

Is a day always 86,400 epoch seconds long? Question: While reviewing my past answers, I noticed I’d proposed code such as this: import time def dates_between(start, end): # muck around between the 9k+ time representation systems in Python # now start and end are seconds since epoch # return [start, start + 86400, start + …

Total answers: 4

How can I convert a datetime object to milliseconds since epoch (unix time) in Python?

How can I convert a datetime object to milliseconds since epoch (unix time) in Python? Question: I have a Python datetime object that I want to convert to unix time, or seconds/milliseconds since the 1970 epoch. How do I do this? Asked By: SuperString || Source Answers: >>> import datetime >>> # replace datetime.datetime.now() with …

Total answers: 14

In Python, how do you convert seconds since epoch to a `datetime` object?

In Python, how do you convert seconds since epoch to a `datetime` object? Question: The time module can be initialized using seconds since epoch: >>> import time >>> t1=time.gmtime(1284286794) >>> t1 time.struct_time(tm_year=2010, tm_mon=9, tm_mday=12, tm_hour=10, tm_min=19, tm_sec=54, tm_wday=6, tm_yday=255, tm_isdst=0) Is there an elegant way to initialize a datetime.datetime object in the same way? Asked …

Total answers: 5