Fix Python – How to preserve timezone when parsing date/time strings with strptime()?

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):
Tue Jun 22 07:46:22 EST 2010

I need to be able to parse this date in Python. At first, I tried to use the strptime() function from datettime.
>>> datetime.datetime.strptime(‘Tue ….

Fix Python – How to convert a UTC datetime to a local datetime using only standard library?

I have a python datetime instance that was created using datetime.utcnow() and persisted in database.
For display, I would like to convert the datetime instance retrieved from the database to local datetime using the default local timezone (i.e., as if the datetime was created using
How can I convert the UTC datetime to a local da….

Fix Python – Can’t subtract offset-naive and offset-aware datetimes

I have a timezone aware timestamptz field in PostgreSQL. When I pull data from the table, I then want to subtract the time right now so I can get it’s age.
The problem I’m having is that both and datetime.datetime.utcnow() seem to return timezone unaware timestamps, which results in me getting this error:
TypeError: can’t s….

Fix Python – How do I get a value of in Python that is “timezone aware”?

I am trying to subtract one date value from the value of to calculate how long ago something was. But it complains:
TypeError: can’t subtract offset-naive and offset-aware datetimes

The return value from doesn’t seem to be “timezone aware”, while my other date value is. How do I get a return val….

Fix Python – How to make a timezone aware datetime object

What I need to do
I have a timezone-unaware datetime object, to which I need to add a time zone in order to be able to compare it with other timezone-aware datetime objects. I do not want to convert my entire application to timezone unaware for this one legacy case.
What I’ve Tried
First, to demonstrate the problem:
Python 2.6.1 (r261:67515, Jun 2….