Using timezone with datetime in python

>>> import pytz
>>> import datetime
>>> tz = pytz.timezone('Asia/Calcutta')
>>> tz
<DstTzInfo 'Asia/Calcutta' HMT+5:53:00 STD>
>>> t = tz.localize(datetime.datetime(2014, 4, 5, 6, 7, 8, 900))
>>> t
datetime.datetime(2014, 4, 5, 6, 7, 8, 900, tzinfo=<DstTzInfo 'Asia/Calcutta' IST+5:30:00 STD>)
>>> t.isoformat()
'2014-04-05T06:07:08.000900+05:30'

Reference: Python datetime object show wrong timezone offset

Comments

Pages

Categories

Tags