Questions tagged [pytz]

pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.3 or higher. It also solves the issue of ambiguous times at the end of daylight savings.

pytz brings the Olson tz database into Python. This library allows accurate and cross platform timezone calculations using Python 2.3 or higher. It also solves the issue of ambiguous times at the end of daylight savings.

717 questions
7
votes
1 answer

Converting local time to UTC using pytz adds DST?

>>> t = datetime.datetime(2016, 11, 27, 14, 46, 0, 0) tz = pytz.timezone('America/Vancouver') utc = tz.localize(t).astimezone(pytz.utc) now = datetime.datetime.utcnow() >>> print t, tz, utc, now 2016-11-27 14:46:00 America/Vancouver 2016-11-27…
Rastio
  • 1,506
  • 1
  • 13
  • 18
7
votes
2 answers

Pandas convert datetime with a separate time zone column

I have a dataframe with a column for the time zone and a column for the datetime. I would like to convert these to UTC first to join with other data, and then I'll have some calculations to convert from UTC to the viewers local time zone…
trench
  • 5,075
  • 12
  • 50
  • 80
7
votes
3 answers

Comparison of two `time` objects with different timezones

I'm comparing two time objects with different timezones, and looks like it's actually ignoring the timezone, testing only the hour/minute/second components. Let's create two time objects: from datetime import time import pytz CET =…
kolypto
  • 31,774
  • 17
  • 105
  • 99
7
votes
1 answer

How to set the offset of timestamps in a pandas dataframe?

I'm having a DataFrame with two columns. One column is filled with timestamps, the other column contains the offset in hours to UTC of the timestamp in the same row. The DataFrame looks like this: In [44]: df Out[44]: DATETIME …
THM
  • 745
  • 2
  • 8
  • 14
7
votes
1 answer

Difference between pytz.UTC and pytz.timezone('GMT')

pytz's documentation says: Note that this instance [pytz.timezone('UTC')] is not the same instance (or implementation) as other timezones with the same meaning (GMT, Greenwich, Universal, etc.). and indeed: >>> pytz.timezone('UTC') is…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
6
votes
3 answers

Python APScheduler fails: 'Only timezones from the pytz library are supported' error

I am trying to run a python async app with an asyncioscheduler scheduled job but the APScheduler fails during build because of this error: 'Only timezones from the pytz library are supported' error I do include pytz in my app and i am passing the…
KZiovas
  • 3,491
  • 3
  • 26
  • 47
6
votes
0 answers

Find whether timezone name is deprecated in pytz

In order to make my API return proper timezone strings (with proper, I mean any that are not marked "deprecated" in the latest specification; so that the consumer of the API has some guarantee on what the valid values are), I would like to check in…
Claude
  • 8,806
  • 4
  • 41
  • 56
6
votes
1 answer

Deal with Birtish summer time

I have a date string 18 May 14:30 which corresponds to the British summertime (WEST or UTC+1). I would like to convert it to central Euopean (summer)time. Here is my code # from datetime import datetime # from pytz import timezone d = '18 May…
user101
  • 476
  • 1
  • 4
  • 9
6
votes
2 answers

Pig: is it possible to use pytz or dateutils for Python udfs?

I am using datetime in some Python udfs that I use in my pig script. So far so good. I use pig 12.0 on Cloudera 5.5 However, I also need to use the pytz or dateutil packages as well and they dont seem to be part of a vanilla python install. Can I…
ℕʘʘḆḽḘ
  • 18,566
  • 34
  • 128
  • 235
6
votes
2 answers

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

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…
Jiminion
  • 5,080
  • 1
  • 31
  • 54
6
votes
1 answer

Python datetime + pytz issue

I'm creating a datetime object via strptime, set to "2016-01-02 03:04:05" in the "Europe/Madrid" timezone via pytz. Then I'm converting it to UTC. Why does it add 15 minutes instead of subtract 1 hour? >>> import datetime >>> import pytz >>> d =…
Nick Jensen
  • 411
  • 4
  • 5
6
votes
1 answer

Python-Django timezone is not working properly

I am working on Django based website. I am trying to get correct timezone and time to be displayed. But it is not working properly. I live in Dallas, Texas. So my default timezone is 'America/Chicago'. My settings.py file has these lines of code.…
Django Learner
  • 323
  • 1
  • 4
  • 12
6
votes
1 answer

How to get the first datetime of a day?

Using pytz and Python 3.4, how to get the first datetime of a given day (lets say, 2014-10-19), in a given timezone (lets say 'America/Sao_Paulo')?
lvella
  • 12,754
  • 11
  • 54
  • 106
6
votes
2 answers

I am getting 'ZZ' as country code when using pytz

I am using App engine, and I'm trying to get the time zone from the request. However when on local host it always seems to return 'ZZ' as the country code which is not a country in pytz library. This code: country =…
Alec Hewitt
  • 805
  • 1
  • 12
  • 21
6
votes
4 answers

How to find next day's Unix timestamp for same hour, including DST, in Python?

In Python, I can find the Unix time stamp of a local time, knowing the time zone, like this (using pytz): >>> import datetime as DT >>> import pytz >>> mtl = pytz.timezone('America/Montreal') >>> naive_time3 = DT.datetime.strptime('2013/11/03',…
eepp
  • 7,255
  • 1
  • 38
  • 56