Showing posts with label convert. Show all posts
Showing posts with label convert. Show all posts

Thursday, March 26, 2009

Convert time zone from US to India

This shows the steps to convert time zones from EST to IST

>>> from datetime import datetime
>>> from pytz import timezone
>>> us_tz = timezone("US/Eastern")
>>> in_tz = timezone("Asia/Calcutta")
>>> now = datetime.now()
>>> dt_in = in_tz.localize(now)
>>> dt_us = dt_in.astimezone(us_tz)
>>> dt_in
datetime.datetime(2009, 3, 26, 12, 58, 17, 909000, tzinfo=)
>>> dt_us
datetime.datetime(2009, 3, 26, 3, 28, 17, 909000, tzinfo=)
>>> dt_in.year
2009
>>> dt_in.month
3
>>> datetime.weekday(dt_in)
3
>>> dt_in.hour
12
>>> dt_in.minute
58
>>> dt_in.second
17
>>>