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
5
votes
2 answers

Django timezone.make_aware raised AmbiguousTimeError for 2014-10-26 1:45:00

I found some strange things. Here some examples. from django.utils import timezone value = u'2014-10-26 01:45:00' #I know that a variable has 'Europe / Moscow' timezone. Let's tell Django about it. TZ = timezone.pytz.timezone('Europe/Moscow') d =…
hloroform
  • 133
  • 7
5
votes
1 answer

Python timezone full names

pytz provides list of timezones in formats like America/Chicago, America/Los_Angeles, Asia/Kolkata or the tz abbreviation. I want the full name for timezones. Central Standard Time Pacific Standard Time Indian Standard Time Is this possible in…
MavWolverine
  • 846
  • 1
  • 9
  • 24
5
votes
1 answer

Calculate time in a different timezone in Python

I'm working with a dataset with timestamps from two different time zones. Below is what I am trying to do: 1.Create a time object t1 from a string; 2.Set the timezone for t1; 3.Infer the time t2 at a different timezone. import time s = "2014-05-22…
jinlong
  • 839
  • 1
  • 9
  • 19
5
votes
2 answers

Converting an un-aware timestamp into an aware timestamp for UTC conversion

I created a datetime that is unaware using the code below and I need to have it in UTC since the time is in "US/Eastern". I would like to make the datetime aware of EST first then convert to UTC. import datetime import pytz from pytz import…
Tampa
  • 75,446
  • 119
  • 278
  • 425
5
votes
4 answers

How to manage timezones in a web application?

I wan't to manage the different timezones of my users in my web application, but I have no idea where to start. I have to save the local time of each user in my database?, or maybe make the conversion to a UTC time, save it, and then make the…
segaco
  • 1,226
  • 5
  • 19
  • 30
5
votes
1 answer

Providing pytz version in setup.py requirements

The problem I wanted to include requirement for pytz in setup.py script in my library, but wanted also to set the minimal version required. But the version numbers used by pytz module (eg. "2012f") seem to be incompatible with what distutils wants…
Tadeck
  • 132,510
  • 28
  • 152
  • 198
5
votes
1 answer

Convert non-UTC time string with timezone abbreviation into UTC time in python, while accounting for daylight savings

I am having a hard time converting a string representation of non-UTC times to UTC due to the timezone abbreviation. (update: it seems that the timezone abbreviations may not be unique. if so, perhaps i should also be trying to take this into…
snakesNbronies
  • 3,619
  • 9
  • 44
  • 73
4
votes
3 answers

Module pytz was already imported

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…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
4
votes
2 answers

Is there a way to infer in Python if a date is the actual day in which the DST (Daylight Saving Time) change is made?

I would like to infer in Python if a date is the actual day of the year in which the hour is changed due to DST (Daylight Saving Time). With the library pytz you can localize a datetime and the actual DST change is correctly done. Furthermore, there…
IgnacioGaBo
  • 168
  • 11
4
votes
1 answer

isoformat function of datetime module in python returns incorrect offset

So I have - timezone = pytz.timezone('Asia/Kolkata') one_time_stamp = '2017-06-01 05:30:00' zoned_time_stamp = datetime.datetime.strptime(one_time_stamp, '%Y-%m-%d %H:%M:%S') #This outputs 2017-06-01 05:30:00 which is…
Mohammad Adnan
  • 6,527
  • 6
  • 29
  • 47
4
votes
3 answers

converting from local to utc timezone

I'm attempting to craft a function that takes a time object and converts it to UTC time. The code below appears to be off by one hour. When i run noon through the converter, i get back 18:00:00. But when i run the same data through online…
nnachefski
  • 1,552
  • 2
  • 18
  • 29
4
votes
2 answers

How to create a Timezone aware Time object that works with all dates?

I have been struggling with this issue for a while now. I feel that I understand Timezones well, and I think I understand how to use pytz properly so I usually use that and I typically don't have any problems. Maybe I am trying to use the wrong…
mvanb
  • 55
  • 4
4
votes
2 answers

Is datetime.replace fundamentally broken?

Converting a timezone naive date time to a specific timezone gives a completely incorrect result. import dateutil as du import pytz du.parser.parse('2017-05-31T15:00:00').replace(tzinfo=pytz.timezone('Europe/London')).isoformat() returns a one…
Ymareth
  • 649
  • 4
  • 15
4
votes
1 answer

datetime ignores tzinfo?

I'm probably misunderstanding the purpose of tzinfo, but I have a datetime object dt I managed to get into this form: datetime.datetime(2017, 7, 2, 20, 0, tzinfo=tzoffset('PDT', -7)) I'm trying to represent the above date from July 2nd 2017 20:00…
K2xL
  • 9,730
  • 18
  • 64
  • 101
4
votes
2 answers

Why a timezone aware datetime's tzinfo does not equal the timezone?

>>> import pytz >>> tz = pytz.timezone('America/Chicago') >>> dt_naive = datetime(year=2017, month=6, day=6) >>> dt_aware = tz.localize(dt_naive) >>> dt_aware.tzinfo == tz False What's the reason for these to differ? >>> dt_aware.tzinfo
wim
  • 338,267
  • 99
  • 616
  • 750