1

I have a string similar to "2012-06-14 20:38:24.213-7:00" and want to convert it to a python date time object with the time zone kept intact, how would I do this?

Jamal Khan
  • 9,371
  • 6
  • 23
  • 23

1 Answers1

1

A fixed offset is not enough to find out the timezone name.

Otherwise pytz and/or dateutil libraries might help:

>>> from dateutil import parser
>>> parser.parse('2012-06-14 20:38:24.213-7:00')
datetime.datetime(2012, 6, 14, 20, 38, 24, 213000, tzinfo=tzoffset(None, -25200))
Community
  • 1
  • 1
jfs
  • 399,953
  • 195
  • 994
  • 1,670