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
23
votes
4 answers

Daylight savings time in Python

I am writing a program which deals a lot with timezones and crossing them. The two things I deal with most are creating a datetime object from "now" and then localizing a naive datetime object. To create a datetime object from now in the pacific…
jmetz
  • 815
  • 1
  • 9
  • 19
22
votes
5 answers

What's the difference between pytz and dateutil?

I'm trying to implement timezone awareness in my Python application, and I have come across two different Python modules that implement this feature: pytz and python-dateutil. What is the difference between these two modules? (pytz)…
fangsterr
  • 3,670
  • 4
  • 37
  • 54
22
votes
1 answer

Python: How to convert a timezone aware timestamp to UTC without knowing if DST is in effect

I am trying to convert a naive timestamp that is always in Pacific time to UTC time. In the code below, I'm able to specify that this timestamp I have is in Pacific time, but it doesn't seem to know that it should be an offset of -7 hours from UTC…
user1152532
  • 697
  • 3
  • 7
  • 15
22
votes
1 answer

pytz.timezone shows weird results for Asia/Calcutta?

Possible Duplicate: Python datetime object show wrong timezone offset import pytz, datetime pytz.timezone("Asia/Calcutta") prints the following: < DstTzInfo 'Asia/Calcutta' HMT+5:53:00 STD > Why it is not 05:30 hrs? I am in time zone…
Rajat
  • 1,766
  • 2
  • 21
  • 42
21
votes
2 answers

How do you convert a naive datetime to DST-aware datetime in Python?

I'm currently working on the backend for a calendaring system that returns naive Python datetimes. The way the front end works is the user creates various calendar events, and the frontend returns the naive version of the event they created (for…
Jay
  • 291
  • 1
  • 2
  • 6
20
votes
1 answer

pytz.astimezone not accounting for daylight savings?

On 2013 Jun 1 I expect the "PST8PDT" timezone to behave like GMT+7, as it is daylight savings in that timezone. However, it behaves like GMT+8: >>> import pytz, datetime >>> Pacific = pytz.timezone("PST8PDT") >>> datetime.datetime(2013, 6, 1, 12,…
dholstius
  • 1,007
  • 1
  • 7
  • 16
20
votes
3 answers

Localizing Epoch Time with pytz in Python

Im working on converting epoch timestamps to dates in different timezones with pytz. What I am trying to do is create a DateTime object that accepts an Olson database timezone and an epoch time and returns a localized datetime object. Eventually I…
mobiusinversion
  • 343
  • 1
  • 6
  • 17
19
votes
5 answers

Get system local timezone in python

Seems strange, but I cannot find an easy way to find the local timezone using pandas/pytz in Python. I can do: >>> pd.Timestamp('now', tz='utc').isoformat() Out[47]: '2016-01-28T09:36:35.604000+00:00' >>> pd.Timestamp('now').isoformat() Out[48]:…
ntg
  • 12,950
  • 7
  • 74
  • 95
19
votes
2 answers

Python pytz: convert local time to utc. Localize doesn't seem to convert

I have a database that stores datetime as UTC. I need to look up info from a particular time, but the date and time are given in a local time, let's say 'Europe/Copenhagen'. I'm given these as: year = 2012; month = 12; day = 2; hour = 13; min =…
user984003
  • 28,050
  • 64
  • 189
  • 285
19
votes
2 answers

Get country code for timezone using pytz?

I'm using pytz. I've read through the entire documentation sheet, but didn't see how this could be done. I have a timezone: America/Chicago. All I want is to get the respective country code for this timezone: US. It shows that I can do the…
Snowman
  • 31,411
  • 46
  • 180
  • 303
18
votes
1 answer

dateutil and pytz give different results

I have an issue comparing outputs with dateutil and pytz. I'm creating a aware datetime object (UTC) and then converting to a given time zone, but I get different answers. I suspect that dateutil sometimes gives wrong results because it has problems…
r_31415
  • 8,752
  • 17
  • 74
  • 121
16
votes
1 answer

How to determine when DST starts or ends in a specific location in Python?

I'm looking for a method of determining when DST starts or ends for a given timezone in a Python script I'm working on. I know pytz can convert the UTC dates I'm working into localtime, and will take DST into account, however for this particular…
Smingos
  • 280
  • 1
  • 3
  • 9
16
votes
1 answer

Python pytz Converting a timestamp (string format) from one timezone to another

I have a timestamp with timezone information in string format and I would like to convert this to display the correct date/time using my local timezone. So for eg... I have timestamp1 = 2011-08-24 13:39:00 +0800 and I would like to convert this to…
Angela
  • 1,671
  • 3
  • 19
  • 29
16
votes
1 answer

Datetime Timezone conversion using pytz

This is just another post on pytz. There are two functions to convert datetime objects between two timezones. The second functions works for all cases. The first function fails in two cases, (3) and (4). Similar SO post did not have an issue like…
Asif Rehan
  • 983
  • 2
  • 8
  • 25
16
votes
2 answers

Is a specific timezone using DST right now?

How would I get my python script to check whether or not a specific timezone that is stored in a variable using DST right now? My server is set to UTC. So I have say for instance zonename = Pacific/Wallis I want to run the query about if it is…
Jonny Flowers
  • 631
  • 1
  • 9
  • 20
1 2
3
47 48