pytz

Pytz convert time to UTC without DST

假装没事ソ 提交于 2019-12-11 16:48:59
问题 I've done a quite a bit of research before posting this, but I can't seem to get the conversion right. I have some data which has timestamps, and some have DST applied, and others don't. I thought the correct way to specify that it's without DST is using the is_dst parameter for pytz. All 3 options give the same offset from UTC, which is incorrect. The offset should be +1000. What's the best way to do this conversion, and why does the is_dst parameter not make any difference? pytz_eastern

Django celery beat pytz error on startup

纵然是瞬间 提交于 2019-12-11 13:52:37
问题 Out of the blue I get the following error when trying to start my dev server with celery and celery beat. One day this thing works next day it doesn't, I haven't changed anything that could explain this. I start my server using foreman and a Procfile.dev like so: Procfile: web: python manage.py runserver celeryd: python manage.py celeryd -E -B --loglevel=INFO --concurrency=3 worker: python manage.py celerycam Command: foreman start -f Procfile.dev Like I said this never gave any errors.

Python: Weird behavior with signs of pytz timezones

£可爱£侵袭症+ 提交于 2019-12-11 12:11:23
问题 I'm in Argentina, my time is GMT-3 (http://wwp.greenwichmeantime.com/time-zone/south-america/argentina/) I was playing with Pytz and noticed something weird, take a look: from pytz import timezone bsas = timezone('America/Argentina/Buenos_Aires') gmt_plus_3 = timezone('Etc/GMT+3') gmt_min_3 = timezone('Etc/GMT-3') # Date and time at this momement: 2012-07-26 10:23:01 fmt = '%Y-%m-%dT%H:%M:%S' datetime.now(bs).strftime(fmt) #'2012-07-26T10:23:01' <-- GOOD! datetime.now(gmt_min_3).strftime(fmt)

datetime.now in python different when running locally and on server

拈花ヽ惹草 提交于 2019-12-11 11:07:54
问题 I am using Heroku to run some python code. The code that i have written uses a predefined time like example: 16:00 and compares that with the current time and the calculates the difference like this: now = datetime.datetime.now() starttime = datetime.datetime.combine(datetime.date.today(), datetime.time(int(hour), int(minute))) dif = now - starttime Running this locally ofc uses the time in my system i guess and everything is correct. However when i post it on the server and run it there the

How to use abbreviated timezone name(PST, IST) in Pytz

£可爱£侵袭症+ 提交于 2019-12-11 11:06:59
问题 I need to know the way of using Abbreviated timezone name like PST, IST etc on pytz. Now I can be able to convert between timezone using the timezone name like "America/Los_Angeles". Instead I need to find the way of using timezone name like PST, IST etc., Sample code I have used now for conversion. def local2utc(self, dt): from_zone = tz.gettz('America/Los_Angeles') to_zone = tz.gettz('UTC') local = dt.replace(tzinfo=from_zone) print("converted time") print(local.astimezone(to_zone).replace

Converting datetime from one time zone to another using pytz

一笑奈何 提交于 2019-12-11 09:37:43
问题 I have a data set which includes date/timestamps from New York WITHOUT timezone information. EDT or EST are not recorded. Dates include daily data for several years, so it includes both: EDT Timezone EST Timezone I want to translate those date/timestamps to Frankfurt time. This involves using: CET Timezone CEST Timezone Depending on the specific date. I have seen that for the NY time, pytz includes timezone('US/Eastern') , which if I understood correctly includes both timezones (New York

Why isn't the offset of Samoa +13 or +14 when using pytz?

回眸只為那壹抹淺笑 提交于 2019-12-11 08:58:32
问题 I've just read BBC: Samoa and Tokelau skip a day for dateline change, 30.12.2011 I wanted to see this with pytz , but everything I tried only showed an offset of -11, but not of +13 or +14: >>> import pytz >>> tz = pytz.timezone('Pacific/Samoa') >>> tz_us = pytz.timezone('US/Samoa') >>> import datetime >>> datetime.datetime(2011, 12, 30, 9, 00, tzinfo=datetime.timezone.utc).astimezone(tz).isoformat() '2011-12-29T22:00:00-11:00' >>> datetime.datetime(2011, 12, 30, 10,00, tzinfo=datetime

pytz.timezone('Asia/Chongqing') is behaving strangely

 ̄綄美尐妖づ 提交于 2019-12-11 04:18:19
问题 I am writing some Python (Python 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32, Windows 7) code which needs to handle timezones. For this I am using the pytz library (2012d version) which to be on the safe-side I've just updated using easy_install. I specifically need to express times in Chengdu, Sichuan province, PRC. This is in the 'Asia/Chongqing' timezone which should be +07:00 hours ahead of 'Europe/London' (which is my local timezone) For some reason when I

Using python to determine if a timestamp is under daylight savings time

冷暖自知 提交于 2019-12-11 00:25:02
问题 This does not work: t = os.path.getmtime(filename) dTime = datetime.datetime.fromtimestamp(t) justTime = dTime.timetuple() if justTime.tm_isdst == 0 : tDelta = datetime.timedelta(hours=0) else: tDelta = datetime.timedelta(hours=1) What happens instead is that the conditional always equals 1, despite some of the timestamps being within daytime savings time. I am trying to make a python call match the behavior of a c-based call. 回答1: To find out whether a given timestamp corresponds to daylight

Is it possible to get a timezone in Python given a UTC timestamp and a UTC offset?

六眼飞鱼酱① 提交于 2019-12-10 18:39:44
问题 I have data that is the UTC offset and the UTC time. Given that, is it possible in Python to get the user's local timezone (mainly to figure if it is DST etc. probably using pytz), similar to the function in PHP timezone_name_from_abbr ? For example: If my epoch time is 1238720309, I can get the UTC time as: >>> d = datetime.utcfromtimestamp(1238720309) >>> print d + dt.timedelta(0,-28800) #offset for pacific I think 2009-04-02 17:04:41.712143 This is correct except it is PDT right now, so it