pytz

when does `datetime.now(pytz_timezone)` fail?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 14:16:35
问题 delorean docs show this way to get the current time in a given timezone using datetime: from datetime import datetime from pytz import timezone EST = "US/Eastern" UTC = "UTC" d = datetime.utcnow() utc = timezone(UTC) est = timezone(EST) d = utc.localize(d) d = est.normalize(EST) and compare it with the delorian-based code: from delorean import Delorean EST = "US/Eastern" d = Delorean(timezone=EST) I believe the datetime example should be written as: from datetime import datetime import pytz

Use Python to find out if a timezone currently in daylight savings time [duplicate]

戏子无情 提交于 2019-11-26 14:07:37
问题 This question already has an answer here: Is a specific timezone using DST right now? 1 answer We have a server that runs on GMT time. I need to write a Python script that determines if it's currently (at this very second) Daylight Savings Time (DST) in Los Angeles, CA. How can I accomplish this? I took a look at pytz and time, but I can't figure it out. I realize that I could create some logic such as comparing the current time in LA to GMT time, but it would be a lot cleaner if I could use

unexpected results converting timezones in python

Deadly 提交于 2019-11-26 12:43:16
问题 I\'m trying to understand why I\'m getting these results when converting timezones to UTC: In [74]: d1 = datetime(2007, 12, 5, 6, 30,tzinfo=pytz.timezone(\'US/Pacific\')) In [75]: d1 Out[75]: datetime.datetime(2007, 12, 5, 6, 30, tzinfo=<DstTzInfo \'US/Pacific\' LMT-1 day, **16:07:00 STD**>) In [76]: d1.astimezone(pytz.utc) Out[76]: datetime.datetime(2007, 12, 5, 14, 23, tzinfo=<UTC>) Why did 6:30am become 2:23pm? On the other hand, if I use the following approach, I get the expected result:

Could not find a version that satisfies the requirement pytz

喜欢而已 提交于 2019-11-26 12:08:20
问题 I have a problem installing pytz in virtualenv. Downloading/unpacking pytz Could not find a version that satisfies the requirement pytz (from versions: 2009r, 2008b, 2009f, 2008c, 2007g, 2011g, 2005m, 2011e, 2007f, 2011k, 2007k, 2006j, 2008h, 2008i, 2011e, 2008a, 2009e, 2006g, 2011j, 2010l, 2005m, 2008i, 2005k, 2008g, 2007c, 2007i, 2009l, 2009r, 2006j, 2011k, 2007d, 2006p, 2009i, 2009u, 2007i, 2009f, 2010g, 2008h, 2009a, 2007g, 2011e, 2006p, 2012b, 2010k, 2005r, 2007f, 2009l, 2009p, 2008c,

How to get system timezone setting and pass it to pytz.timezone?

一个人想着一个人 提交于 2019-11-26 11:22:29
We can use time.tzname get a local timezone name, but that name is not compatible with pytz.timezone . In fact, the name returned by time.tzname is ambiguous. This method returns ('CST', 'CST') in my system, but 'CST' can indicate four timezones: Central Time Zone (North America) - observed in North America's Central Time Zone China Standard Time Chungyuan Standard Time - the term "Chungyuan Standard Time" is now rarely in use in Taiwan Australian Central Standard Time (ACST) tzlocal module returns pytz tzinfo's object corresponding to the local timezone: import time from datetime import

pytz localize vs datetime replace

梦想与她 提交于 2019-11-26 09:44:04
问题 I\'m having some weird issues with pytz\'s .localize() function. Sometimes it wouldn\'t make adjustments to the localized datetime: .localize behaviour: >>> tz <DstTzInfo \'Africa/Abidjan\' LMT-1 day, 23:44:00 STD> >>> d datetime.datetime(2009, 9, 2, 14, 45, 42, 91421) >>> tz.localize(d) datetime.datetime(2009, 9, 2, 14, 45, 42, 91421, tzinfo=<DstTzInfo \'Africa/Abidjan\' GMT0:00:00 STD>) >>> tz.normalize(tz.localize(d)) datetime.datetime(2009, 9, 2, 14, 45, 42, 91421, tzinfo=<DstTzInfo \

How to add timezone into a naive datetime instance in python [duplicate]

有些话、适合烂在心里 提交于 2019-11-26 09:01:36
问题 This question already has an answer here: How to make an unaware datetime timezone aware in python 9 answers I\'ve got a datetime which has no timezone information. I\'m now getting the timezone info and would like to add the timezone into the existed datetime instance, how can I do? d = datetime.datetime.now() tz = pytz.timezone(\'Asia/Taipei\') How to add the timezone info tz into datetime a 回答1: Use tz.localize(d) to localize the instance. From the documentation: The first is to use the

Datetime Timezone conversion using pytz

不羁岁月 提交于 2019-11-26 04:26:40
问题 This is just another post on pytz . There are two functions to convert datetime objects between two timezones. The second functions works for all cases. The first function fails in two cases, (3) and (4). Similar SO post did not have an issue like this. Any explanation based on the difference between localize(datetime.datetime) and replace(tzinfo) would be a great help. >>> from dateutil.parser import parse >>> import pytz First function (buggy) The function below uses datetime.datetime

Python datetime object show wrong timezone offset

一曲冷凌霜 提交于 2019-11-26 03:58:56
问题 I am try creating a datetime object in python using datetime and pytz, the offset shown is wrong. import datetime from pytz import timezone start = datetime.datetime(2011, 6, 20, 0, 0, 0, 0, timezone(\'Asia/Kolkata\')) print start The output shown is datetime.datetime(2011, 6, 20, 0, 0, tzinfo=<DstTzInfo \'Asia/Kolkata\' HMT+5:53:00 STD>) Note that \'Asia/Kolkata\' is IST which is GMT+5:30 and not HMT+5:53. This is a standard linux timezone, why do I get this wrong, and how do I solve it? 回答1

Weird timezone issue with pytz

喜你入骨 提交于 2019-11-26 03:58:53
问题 >>> import pytz >>> pytz.timezone(\'Asia/Hong_Kong\') <DstTzInfo \'Asia/Hong_Kong\' LMT+7:37:00 STD> A seven hour and 37 minute offset? This is a little strange, does anyone experience the same issue? In fact I\'m getting different behavior between import pytz from datetime import datetime hk = pytz.timezone(\'Asia/Hong_Kong\') dt1 = datetime(2012,1,1,tzinfo=hk) dt2 = hk.localize(datetime(2012,1,1)) if dt1 > dt2: print \"Why?\" 回答1: Time zones and offsets change over the years. The default