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

First call to pytz.timezone is slow in virtualenv

I have installed pytz (v2013.8, but it happens in 2013.b, 2011k) in a virtualenv. The first call to pytz.timezone("US/Eastern") takes about 4 seconds. In a regular environment this is essentially instantaneous. Does anyone have a trick to get…
Mark
  • 229
  • 1
  • 8
8
votes
2 answers

Python - From DST-adjusted local time to UTC

A specific bank has branches in all major cities in the world. They all open at 10:00 AM local time. If within a timezone that uses DST, then of course the local opening time also follows the DST-adjusted time. So how do I go from the local time to…
Erik Ninn-Hansen
  • 565
  • 2
  • 7
  • 16
8
votes
1 answer

Change time zone depending on the user in django project

I am trying to change the time zone in my project, depending on what the user has selected. To do that I have a field in my database, where I keep all possible locations: timezone = models.CharField(max_length=40, null=True, blank=True,…
Alejandroid
  • 199
  • 1
  • 14
8
votes
5 answers

Python datetime and tzinfo objects (changing minutes instead of hours)

I'm trying to apply a tzinfo to a datetime object. In [1]: from datetime import datetime In [2]: import pytz In [3]: london = pytz.timezone("Europe/London") In [4]: london Out[5]: In [6]:…
Sifnos
  • 1,161
  • 2
  • 13
  • 22
8
votes
2 answers

Django and time zone

Django 1.7, PostgreSQL. I want to store datetime in UTC and display it in PST time zone. My local time: 8:05 am UTC time: 1:05 am PST time: 6:05 pm Django doc: When support for time zones is enabled, Django stores date and time information in UTC…
Tom
  • 787
  • 1
  • 12
  • 28
8
votes
1 answer

Python pytz: non-existent time gets AmbiguousTimeError, not NonExistentTimeError

How can I tell if a local time is non-existent? I'm trying with pytz, but it throws an AmbiguousTimeError, not a NonExistentTimeError. 2013-3-31 02:30 will never happen in Copenhagen due to daylight savings time. local_tz =…
user984003
  • 28,050
  • 64
  • 189
  • 285
8
votes
4 answers

Time Zone names in local language

Is there a method to retrieve time zone names in another language? In Python, if I do something like this: for tz in pytz.common_timezones_set : print tz The result is in English, but what if I would like to have it in Spanish or Arabic?
Trollbane
  • 327
  • 1
  • 5
8
votes
1 answer

How to store a naive datetime in Django 1.4

I have a naive date and time in the format '2012-05-19 19:13:00' and need to store it using Django 1.4 and its timezone-aware abilities. Although there is no way of knowing what timezone the date is originally in, it seems to make sense to store it…
Phil Gyford
  • 13,432
  • 14
  • 81
  • 143
7
votes
1 answer

Python DST & Time Zone Detection After Addition

So I currently have a line of code which looks like this: t1 = datetime(self.year, self.month, self.day, self.hour, self.minute, self.second) ... t2 = timedelta(days=dayNum, hours=time2.hour, minutes=time2.minute,…
Dave McGinnis
  • 585
  • 4
  • 17
7
votes
1 answer

Issue with python/pytz Converting from local timezone to UTC then back

I have a requirement to convert a date from a local time stamp to UTC then back to the local time stamp. Strangely, when converting back to the local from UTC python decides it is PDT instead of the original PST so the post converted date has…
user578888
  • 117
  • 4
7
votes
6 answers

Flag Daylight Saving Time (DST) Hours in Pandas Date-Time Column

I created an hourly dates dataframe, and now I would like to create a column that flags whether each row (hour) is in Daylight Saving Time or not. For example, in summer hours, the flag should == 1, and in winter hours, the flag should == 0. #…
Sean McCarthy
  • 4,838
  • 8
  • 39
  • 61
7
votes
1 answer

Why do I get the offset 0:53 for timezone Europe/Berlin?

Example Code from datetime import datetime, timezone import pytz tzstring = 'Europe/Berlin' t1 = datetime(2016, 6, 16, 2, 0, tzinfo=pytz.timezone(tzstring)) t2 = datetime(2016, 6, 16, 2, 0,…
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
7
votes
1 answer

Test if datetime.datetime is in daylight savings with .dst() function not returning value with pytz timezone

I am trying to test if an arbitrary localized datetime object is in daylight savings time or not. This is a similar question to many already asked. eg. (Daylight savings time in Python) In these boards, a way to test if a datetime is in DST is to…
name goes here
  • 280
  • 4
  • 10
7
votes
2 answers

Why python datetime replace timezone is returning different timezone?

I am working on Python/Django project. I am trying to let user select date and time using jQuery plugin datetimepicker add-on. So when I select now option and post data django is saving the time in UTC offset. This is what is saved in database,…
Amit Pandya
  • 361
  • 1
  • 3
  • 19
7
votes
1 answer

Python convert timestamps with specific timezone to datetime in UTC

I'm trying to convert a timestamp with a specific timezone(Europe/Paris) to a datetime format in UTC. From my laptop it works with the solution below but when I'm executing my code in a remote server(AWS- Lambda function in Ireland), I've a shift…
Matt
  • 4,309
  • 7
  • 38
  • 52