I am trying to dateutil.parser.parse()
to parse the default str(datetime.datetime.now())
output using timezone-aware datetimes. However, parse()
seems to lose the timezone information and replace it with the local time timezone. Below is the IPython output:
In [1]: from django.utils.timezone import now
In [3]: import dateutil
In [4]: t = now()
In [6]: print t
2014-07-14 08:51:49.123342+00:00
In [7]: st = unicode(t)
In [8]: print dateutil.parser.parse(st)
2014-07-14 08:51:49.123342+02:00
As far I understood dateutil
does some heurestics when guessing the date format and it might go wrong here.
How to give exact datetime format for parsing timezone-aware datetimes?
Even better - if the format is known how to parse this datetime using only Python stdlib, without dateutil dependency?