Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > datetimes, tzinfo and gmtime epoch

Reply
Thread Tools

datetimes, tzinfo and gmtime epoch

 
 
John Hunter
Guest
Posts: n/a
 
      04-16-2004

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?


s1 = '2-Apr-04' # before dst
s2 = '5-Apr-04' # after dst

y,month,d,h,m,s,wd,jd,ds = time.strptime(s1, '%d-%b-%y')
dt1 = datetime.datetime(y,month,d,h,m,s,tzinfo=Eastern)

y,month,d,h,m,s,wd,jd,ds = time.strptime(s2, '%d-%b-%y')
dt2 = datetime.datetime(y,month,d,h,m,s,tzinfo=Eastern)

print dt1, Eastern.utcoffset(dt1)
print dt2, Eastern.utcoffset(dt2)


But I'm not sure how to convert this to epoch gmtime ....

Thanks,
John Hunter

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
converting datetime with tzinfo to unix timestamp Michael Torrie Python 0 03-12-2010 11:15 PM
Re: [Python 2.x] Pickling a datetime.tzinfo subclass instance? Cong Ma Python 0 12-09-2008 09:56 AM
[Python 2.x] Pickling a datetime.tzinfo subclass instance? Cong Ma Python 0 12-08-2008 02:34 PM
datetime, tzinfo ... strange conversion? Tino Lange Python 1 04-03-2006 09:21 AM
datetime and tzinfo John Hunter Python 0 09-16-2004 01:42 PM



Advertisments