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.
642
questions
884votes
10answers
530kviews
Is there a list of Pytz Timezones?
I would like to know what are all the possible values for the timezone argument in the Python library pytz. How to do it?
680votes
15answers
522kviews
How to make a timezone aware datetime object in Python?
What I need to do
I have a timezone-unaware datetime object, to which I need to add a time zone in order to be able to compare it with other timezone-aware datetime objects. I do not want to convert ...
172votes
1answer
154kviews
How can I remove a pytz timezone from a datetime object?
Is there a simple way to remove the timezone from a pytz datetime object?
e.g. reconstructing dt from dt_tz in this example:
>>> import datetime
>>> import pytz
>>> dt = ...
87votes
4answers
51kviews
How to check if a datetime object is localized with pytz?
I want to store a datetime object with a localized UTC timezone. The method that stores the datetime object can be given a non-localized datetime (naive) object or an object that already has been ...
71votes
6answers
84kviews
How to get system timezone setting and pass it to pytz.timezone?
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 ...
64votes
6answers
79kviews
How do I get the UTC time of "midnight" for a given timezone?
The best I can come up with for now is this monstrosity:
>>> datetime.utcnow() \
... .replace(tzinfo=pytz.UTC) \
... .astimezone(pytz.timezone("Australia/Melbourne")) \
... .replace(...
62votes
4answers
61kviews
pytz localize vs datetime replace
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' ...
61votes
2answers
97kviews
Converting python datetime to timestamp and back in UTC still uses local timezone
I'm working with a code that gives me utc timestamps and I want to convert them to appropriate datetimes. Unfortunately when I test simple cases with pytz the datetime has an added 6 hours (the CST ...
59votes
6answers
76kviews
pytz - Converting UTC and timezone to local time
I have a datetime in utc time zone, for example:
utc_time = datetime.datetime.utcnow()
And a pytz timezone object:
tz = timezone('America/St_Johns')
What is the proper way to convert utc_time to ...
58votes
4answers
17kviews
Python pytz timezone function returns a timezone that is off by 9 minutes
For some reason which I haven't been able to figure out yet, from the the following code:
>>> from pytz import timezone
>>> timezone('America/Chicago')
I get:
<DstTzInfo '...
58votes
2answers
101kviews
Could not find a version that satisfies the requirement pytz
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, ...
57votes
3answers
63kviews
pytz and astimezone() cannot be applied to a naive datetime
I have a date and I need to make it time zone aware.
local_tz = timezone('Asia/Tokyo')
start_date = '2012-09-27'
start_date = datetime.strptime(start_date, "%Y-%m-%d")
start_date = start_date....
53votes
5answers
13kviews
unexpected results converting timezones in python
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....
52votes
2answers
88kviews
How to add timezone into a naive datetime instance in python [duplicate]
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....
52votes
2answers
11kviews
Weird timezone issue with pytz
>>> 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 ...