pytz

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

泪湿孤枕 提交于 2019-11-28 00:56:54
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. 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

Is a specific timezone using DST right now?

我们两清 提交于 2019-11-28 00:49:34
How would I get my python script to check whether or not a specific timezone that is stored in a variable using DST right now? My server is set to UTC. So I have say for instance zonename = Pacific/Wallis I want to run the query about if it is using DST right now and have the reply come back as either true of false. from pytz import timezone from datetime import datetime zonename = "Pacific/Wallis" now = datetime.now(tz=timezone(zonename)) dst_timedelta = now.dst() ### dst_timedelta is offset to the winter time, ### thus timedelta(0) for winter time and timedelta(0, 3600) for DST; ### it

pytz - Converting UTC and timezone to local time

左心房为你撑大大i 提交于 2019-11-27 21:07:38
I have a datetime in utc time zone, for example: utc_time = datetime.datetime.utcnow() And a pytz timezone object: tz = timezone('America/St_Johns') What is the proper way to convert utc_time to the given timezone? Tzach I think I got it: pytz.utc.localize(utc_time, is_dst=None).astimezone(tz) This line first converts the naive (time zone unaware) utc_time datetime object to a datetime object that contains a timezone (UTC). Then it uses the astimezone function to adjust the time according to the requested time zone. May I recommend to use arrow ? If I understood the question: >>> import arrow

pytz and astimezone() cannot be applied to a naive datetime

给你一囗甜甜゛ 提交于 2019-11-27 19:14:43
I have a date and I need to make it time zone aware. local_tz = timezone('Asia/Tokyo') start_date = '2012-09-27' start_date = datetime.strptime(start_date, "%Y-%m-%d") start_date = start_date.astimezone(local_tz) now_utc = datetime.now(timezone('UTC')) local_now = now_utc.astimezone(local_tz) I need to find if this is true: print start_date>local_now But I get this error. start_date = start_date.astimezone(local_tz) ValueError: astimezone() cannot be applied to a naive datetime I convert utc to tokyo with no issue. I need to make start_date timezone aware ad well in tokyo. Thanks For pytz

Timezone Information Missing in pytz?

帅比萌擦擦* 提交于 2019-11-27 18:21:12
问题 I'm having a very weird problem with Python's pytz : it seems to have an incomplete catalog of timezones on my system (MacOS X 10.8.5, system Python 2.7.5). >>> from pytz import timezone >>> import pytz >>> utc = pytz.utc >>> utc.zone 'UTC' >>> eastern = timezone('US/Eastern') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "pytz/__init__.pyc", line 182, in timezone pytz.exceptions.UnknownTimeZoneError: 'US/Eastern' So the timezone 'US/Eastern' can't be found.

how to get tz_info object corresponding to current timezone?

℡╲_俬逩灬. 提交于 2019-11-27 17:14:32
问题 Is there a cross-platform function in python (or pytz ) that returns a tzinfo object corresponding to the timezone currently set on the computer? environment variables cannot be counted on as they are not cross-platform 回答1: >>> import datetime >>> today = datetime.datetime.now() >>> insummer = datetime.datetime(2009,8,15,10,0,0) >>> from pytz import reference >>> localtime = reference.LocalTimezone() >>> localtime.tzname(today) 'PST' >>> localtime.tzname(insummer) 'PDT' >>> 回答2: tzlocal

Module pytz was already imported

给你一囗甜甜゛ 提交于 2019-11-27 16:55:13
问题 I keep getting the following error while running Python code: C:\Python26\lib\site-packages\pytz\__init__.py:32: UserWarning: Module pytz was already imported from C:\Python26\lib\site-packages\pytz\__init__.pyc, but c:\python26\lib\site-packages\pytz-2011h-py2.6.egg is being added to sys.path from pkg_resources import resource_stream What does it mean and how can I solve it? 回答1: You've got the package installed in pytz and also as a .egg . Remove the .egg and you won't get the warning.

UnknownTimezoneError Exception Raised with Python Application Compiled with Py2Exe

纵饮孤独 提交于 2019-11-27 14:50:35
问题 I'm having a problem distributing an application that utilizes pytz . I'm using Py2Exe to create an executable from my Python source. For a simple example of the problem I'm having, I have: pytz_test.py: import pytz tz_au = pytz.timezone("Australia/Sydney") print tz_au and in setup.py: from distutils.core import setup import py2exe setup(console=['pytz_test.py'], options={"py2exe" : { 'packages': ['pytz'], } }) I then run setup.py: python setup.py py2exe Which compiles the executable. Running

get the DST boundaries of a given timezone in python

。_饼干妹妹 提交于 2019-11-27 14:45:54
Is it possible to get the DST boundaries of a given timezone with pytz? It doesn't seem to be officially supported. However, you can poke at the internals of a DstTzInfo object and get it from there: >>> from pytz import timezone >>> tz = timezone('Europe/London') >>> tz._utc_transition_times [datetime.datetime(1, 1, 1, 0, 0), datetime.datetime(1916, 5, 21, 2, 0), ... datetime.datetime(2036, 3, 30, 1, 0), datetime.datetime(2036, 10, 26, 1, 0), datetime.datetime(2037, 3, 29, 1, 0), datetime.datetime(2037, 10, 25, 1, 0)] Each entry corresponds to an entry in _transition_info : >>> tz._transition

pytz: Why is normalize needed when converting between timezones?

被刻印的时光 ゝ 提交于 2019-11-27 14:29:07
问题 I'm reading the not so complete pytz documentation and I'm stuck on understand one part of it. Converting between timezones also needs special attention. This also needs to use the normalize method to ensure the conversion is correct. >>> utc_dt = utc.localize(datetime.utcfromtimestamp(1143408899)) >>> utc_dt.strftime(fmt) '2006-03-26 21:34:59 UTC+0000' >>> au_tz = timezone('Australia/Sydney') >>> au_dt = au_tz.normalize(utc_dt.astimezone(au_tz)) >>> au_dt.strftime(fmt) '2006-03-27 08:34:59