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
968
votes
10 answers

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?
ipegasus
  • 14,796
  • 9
  • 52
  • 76
795
votes
16 answers

How to make a datetime object aware (not naive)

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 my entire application to timezone unaware for this…
Mark Tozzi
  • 10,353
  • 5
  • 22
  • 30
200
votes
1 answer

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 = datetime.datetime.now() >>> dt datetime.datetime(2012, 6, 8, 9, 27, 32,…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
101
votes
4 answers

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 localized. How do I determine if localization is…
chiborg
  • 26,978
  • 14
  • 97
  • 115
80
votes
6 answers

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 system, but 'CST' can indicate four…
user805627
  • 4,247
  • 6
  • 32
  • 43
76
votes
6 answers

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(hour=0,minute=0,second=0,microsecond=0) \ ... …
Tom
  • 42,844
  • 35
  • 95
  • 101
75
votes
2 answers

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 offset to UTC). I need to keep timezone data…
aterrel
  • 1,992
  • 1
  • 14
  • 23
74
votes
4 answers

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 >>> d datetime.datetime(2009, 9, 2,…
Art
  • 23,747
  • 29
  • 89
  • 101
71
votes
4 answers

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: When, I assume, I should…
elethan
  • 16,408
  • 8
  • 64
  • 87
66
votes
6 answers

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 the given timezone?
Tzach
  • 12,889
  • 11
  • 68
  • 115
65
votes
2 answers

How to add timezone into a naive datetime instance in python

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.now() tz = pytz.timezone('Asia/Taipei') How to add…
waitingkuo
  • 89,478
  • 28
  • 112
  • 118
59
votes
4 answers

How do you convert a datetime/timestamp from one timezone to another timezone?

Specifically, given the timezone of my server (system time perspective) and a timezone input, how do I calculate the system time as if it were in that new timezone (regardless of daylight savings, etc)? import datetime current_time =…
kfan
  • 1,641
  • 1
  • 13
  • 16
59
votes
3 answers

Weird timezone issue with pytz

>>> import pytz >>> pytz.timezone('Asia/Hong_Kong') A seven hour and 37 minute offset? This is a little strange, does anyone experience the same issue? In fact I'm getting different behavior…
Arthur B.
  • 3,445
  • 3
  • 21
  • 24
58
votes
2 answers

Python datetime object show wrong timezone offset

I am try creating a datetime object in python using datetime and pytz, the offset shown is wrong. import datetime from pytz import timezone start = datetime.datetime(2011, 6, 20, 0, 0, 0, 0, timezone('Asia/Kolkata')) print start The output shown…
compbugs
  • 775
  • 1
  • 6
  • 10
58
votes
2 answers

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, 2011g, 2005m, 2011e, 2007f, 2011k, 2007k, 2006j,…
Houman
  • 64,245
  • 87
  • 278
  • 460
1
2 3
47 48