2

I wish to convert one time zone(GMT) to another (IST) using python.
My datetime string 2015-08-19 11:11:51 +0000

I am trying to convert datetime object
datetime.datetime.strptime("2015-08-19 11:11:51 %z",'%Y-%m-%d %H:%M:%S +0000')

But I am getting following error
time data '2015-08-19 11:11:51 %z' does not match format '%Y-%m-%d %H:%M:%S +0000'

+0000 refers to time zone diff with respect to GMT.

jfs
  • 399,953
  • 195
  • 994
  • 1,670
onkar
  • 4,427
  • 10
  • 52
  • 89

1 Answers1

1

In Python 2.x, %z is not supported by datetime.datetime.strptime(), you can try switching to Python 3.2.

Alternatively, you can use dateutil.parser.parse() which is 3rd party library:

$ pip install python-dateutil

--

>>> from dateutil.parser import parse
>>> parse("2015-08-19 11:11:51 +0000")
datetime.datetime(2015, 8, 19, 11, 11, 51, tzinfo=tzutc())
Ozgur Vatansever
  • 49,246
  • 17
  • 84
  • 119