How to make a timezone aware datetime object
What I need to do
What I need to do
I have a CSV dumpfile from a Blackberry IPD backup, created using IPDDump.
The date/time strings in here look something like this
(where EST is an Australian time-zone):
Is there an elegant way to display the current time in another time zone?
You can use the function tz_localize to make a Timestamp or DateTimeIndex timezone aware, but how can you do the opposite: how can you convert a timezone aware Timestamp to a naive one, while preserving its timezone?
I have a date string of the form ‘2009/05/13 19:19:30 -0400’. It seems that previous versions of Python may have supported a %z format tag in strptime for the trailing timezone specification, but 2.6.x seems to have removed that.
I have a python datetime instance that was created using datetime.utcnow() and persisted in database.
>>> import pytz >>> pytz.timezone('Asia/Hong_Kong') <DstTzInfo 'Asia/Hong_Kong' LMT+7:37:00 STD> A seven hour and 37 minute offset? This is a little strange, does anyone experience the same issue? In fact I’m getting different behavior between import pytz from datetime import datetime hk = pytz.timezone('Asia/Hong_Kong') dt1 = datetime(2012,1,1,tzinfo=hk) dt2 = hk.localize(datetime(2012,1,1)) if dt1 > dt2: print "Why?" … Read more
I’m trying to parse timestamp strings like "Sat, 11/01/09 8:00PM EST" in Python, but I’m having trouble finding a solution that will handle the abbreviated timezone.
I am trying to subtract one date value from the value of datetime.datetime.today() to calculate how long ago something was. But it complains:
The best I can come up with for now is this monstrosity: