pytz

How to get time zone by passing city and country?

柔情痞子 提交于 2019-11-30 17:47:41
问题 In my django project I have a small hotel database which has fields city and country . Can I get the timezone for that place by passing the city and country as parameters in someway. The reason I want to do this is because I have some commands that work based on the difference in check-in time of hotels and the time at that hote now . Since datetime.now() gives naive datetime I cannot use it to compare with the hotel time. How do I look forward to the solution. Thanks :) 回答1: To resolve a

Python - Setting a datetime in a specific timezone (without UTC conversions)

删除回忆录丶 提交于 2019-11-30 17:12:56
Just to be clear, this is python 2.6, I am using pytz. This is for an application that only deals with US timezones, I need to be able to anchor a date (today), and get a unix timestamp (epoch time) for 8pm and 11pm in PST only. This is driving me crazy. > pacific = pytz.timezone("US/Pacific") > datetime(2011,2,11,20,0,0,0,pacific) datetime.datetime(2011, 2, 11, 20, 0, tzinfo=<DstTzInfo 'US/Pacific' PST-1 day, 16:00:0 STD>) > datetime(2011,2,11,20,0,0,0,pacific).strftime("%s") '1297454400' zsh> date -d '@1297454400' Fri Feb 11 12:00:00 PST 2011 So, even though I am setting up a timezone, and

Python - Setting a datetime in a specific timezone (without UTC conversions)

与世无争的帅哥 提交于 2019-11-30 16:30:41
问题 Just to be clear, this is python 2.6, I am using pytz. This is for an application that only deals with US timezones, I need to be able to anchor a date (today), and get a unix timestamp (epoch time) for 8pm and 11pm in PST only. This is driving me crazy. > pacific = pytz.timezone("US/Pacific") > datetime(2011,2,11,20,0,0,0,pacific) datetime.datetime(2011, 2, 11, 20, 0, tzinfo=<DstTzInfo 'US/Pacific' PST-1 day, 16:00:0 STD>) > datetime(2011,2,11,20,0,0,0,pacific).strftime("%s") '1297454400'

datetime with pytz timezone. Different offset depending on how tzinfo is set [duplicate]

一世执手 提交于 2019-11-30 16:23:48
This question already has an answer here: How to add timezone into a naive datetime instance in python [duplicate] 2 answers I ran across an interesting situation today. Can anyone explain why the offsets for ts1 and ts2 are different? ts1 is a datetime object that is timezone-aware right off the bat. ts2 is a datetime object that starts off timezone-naive and has its tzinfo replaced. However, they end up with different offsets. >>> from pytz import timezone >>> EST = timezone('America/New_York') >>> ts1 = datetime.datetime.now(tz=EST) >>> ts2 = datetime.datetime.now() >>> ts2 = ts2.replace

datetime with pytz timezone. Different offset depending on how tzinfo is set [duplicate]

…衆ロ難τιáo~ 提交于 2019-11-30 16:10:12
问题 This question already has answers here : How to add timezone into a naive datetime instance in python [duplicate] (2 answers) Closed 4 years ago . I ran across an interesting situation today. Can anyone explain why the offsets for ts1 and ts2 are different? ts1 is a datetime object that is timezone-aware right off the bat. ts2 is a datetime object that starts off timezone-naive and has its tzinfo replaced. However, they end up with different offsets. >>> from pytz import timezone >>> EST =

How do you convert a naive datetime to DST-aware datetime in Python?

北慕城南 提交于 2019-11-30 14:46:14
问题 I'm currently working on the backend for a calendaring system that returns naive Python datetimes. The way the front end works is the user creates various calendar events, and the frontend returns the naive version of the event they created (for example, if the user selects October 5, 2020 from 3:00pm-4:00pm, the frontend returns datetime.datetime(2020, 10, 5, 15, 0, 0) as the start and datetime.datetime(2011, 10, 5, 16, 0, 0) as the end. What I need to do is to take the naive datetime and

How to determine when DST starts or ends in a specific location in Python? [duplicate]

三世轮回 提交于 2019-11-30 13:52:23
问题 This question already has an answer here : get the DST boundaries of a given timezone in python (1 answer) Closed 5 years ago . I'm looking for a method of determining when DST starts or ends for a given timezone in a Python script I'm working on. I know pytz can convert the UTC dates I'm working into localtime, and will take DST into account, however for this particular application I need to know the point of the changeover. Any suggestions? 回答1: You could have a look to the _utc_transition

cx_freeze: How do I add package files into library.zip?

断了今生、忘了曾经 提交于 2019-11-30 12:47:57
I've noticed that pytz misses zoneinfo folder when I try to roll a zip for Windows. Right now I have a workaround that I use after python setup.py build , namely 7z a -xr!*.py* build\exe.win32-2.7\library.zip C:\Python27\Lib\site-packages\pytz Is there a proper way to achieve that from setup.py or something? You could fix this, adding the following method: def include_files(): path_base = "C:\\Python27\\Lib\\site-packages\\pytz\\zoneinfo\\" skip_count = len(path_base) zip_includes = [(path_base, "pytz/zoneinfo/")] for root, sub_folders, files in os.walk(path_base): for file_in_root in files:

How do you convert a naive datetime to DST-aware datetime in Python?

空扰寡人 提交于 2019-11-30 11:43:28
I'm currently working on the backend for a calendaring system that returns naive Python datetimes. The way the front end works is the user creates various calendar events, and the frontend returns the naive version of the event they created (for example, if the user selects October 5, 2020 from 3:00pm-4:00pm, the frontend returns datetime.datetime(2020, 10, 5, 15, 0, 0) as the start and datetime.datetime(2011, 10, 5, 16, 0, 0) as the end. What I need to do is to take the naive datetime and convert it into UTC for storage in a database. Each user of the system has already specified their

How to determine when DST starts or ends in a specific location in Python? [duplicate]

寵の児 提交于 2019-11-30 08:47:53
This question already has an answer here: get the DST boundaries of a given timezone in python 1 answer I'm looking for a method of determining when DST starts or ends for a given timezone in a Python script I'm working on. I know pytz can convert the UTC dates I'm working into localtime, and will take DST into account, however for this particular application I need to know the point of the changeover. Any suggestions? You could have a look to the _utc_transition_times memberof the timezone you're using. >>> from pytz import timezone >>> tz = timezone("Europe/Paris") >>> print tz._utc