Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pytz.timezone shows weird results for Asia/Calcutta? [duplicate]

Possible Duplicate:
Python datetime object show wrong timezone offset

import pytz, datetime

 pytz.timezone("Asia/Calcutta")

prints the following:

< DstTzInfo 'Asia/Calcutta' HMT+5:53:00 STD >

Why it is not 05:30 hrs? I am in timezone America/Los_Angeles.

like image 896
Rajat Avatar asked Jul 11 '12 22:07

Rajat


People also ask

Does pytz handle DST?

pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.4 or higher. It also solves the issue of ambiguous times at the end of daylight saving time, which you can read more about in the Python Library Reference ( datetime. tzinfo ).

What is pytz used for?

Pytz brings the Olson tz database into Python and thus supports almost all time zones. This module serves the date-time conversion functionalities and helps user serving international client's base.

How do I remove Tzinfo from datetime?

To remove timestamp, tzinfo has to be set None when calling replace() function. First, create a DateTime object with current time using datetime. now(). The DateTime object was then modified to contain the timezone information as well using the timezone.


1 Answers

Time zones change over the years. According to http://www.prokerala.com/travel/timezones/Asia/Kolkata?mode=history the original offset for that zone was 5.88888888889 hours, or 5 hours 53 minutes. pytz will use the proper offset and nomenclature once you assign the zone to an actual date.

>>> tz = pytz.timezone("Asia/Calcutta")
>>> tz
<DstTzInfo 'Asia/Calcutta' HMT+5:53:00 STD>
>>> tz.localize(datetime.datetime(1901, 7, 10, 12, 0))
datetime.datetime(1901, 7, 10, 12, 0, tzinfo=<DstTzInfo 'Asia/Calcutta' HMT+5:53:00 STD>)
>>> tz.localize(datetime.datetime(2012, 7, 10, 12, 0))
datetime.datetime(2012, 7, 10, 12, 0, tzinfo=<DstTzInfo 'Asia/Calcutta' IST+5:30:00 STD>)
like image 92
Mark Ransom Avatar answered Sep 21 '22 18:09

Mark Ransom