datetimes, tzinfo and gmtime epoch
John Hunter
jdhunter at ace.bsd.uchicago.edu
Fri Apr 16 15:40:02 EDT 2004
>>>>> "Robert" == Robert Brewer <fumanchu at amor.org> writes:
Robert> John Hunter wrote:
>> I have a python2.3 datetime instance and a tzinfo instance (eg
>> Eastern from the python library reference).
>>
>> What is the best way to convert that datetime instance to
>> seconds since the epoch, gmtime?
Robert> You might try time.mktime(t), where t is a 9-tuple as
Robert> desribed at:
Yes, but you still have to account for the offset to gmtime, which is
dependent on daylight savings time.
I *think* this is correct, where x is a datetime instance and tz is a
tzinfo instance.
offset = self.tz.utcoffset(x).days*SEC_PER_DAY + self.tz.utcoffset(x).seconds
gmepoch = time.mktime(x.timetuple())+offset
JDH
More information about the Python-list
mailing list