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

Python pytz: what happens if a country does away with DST?

OK, this is more a curiosity question, but how does pytz know all the daylight savings times (DST)? For example, that 'Europe/Copenhagen' time switches in March and October. Or rather, what happens if a country decides to do away with DST? Will…
user984003
  • 28,050
  • 64
  • 189
  • 285
6
votes
2 answers

PYTZ 'America/Edmonton' offset wrong

Possible Duplicate: Weird timezone issue with pytz This seems wrong: >>> import pytz >>> z1 = timezone('America/Edmonton') >>> z2 = timezone('US/Mountain') >>> z1 >>> z2
Goro
  • 9,919
  • 22
  • 74
  • 108
6
votes
3 answers

Comparing a time in UTC with a time in Eastern time using Python

I'm trying to compare two times using the Python datetime module, but I can't seem to create a timezone-aware time object in UTC. >>> import pytz, datetime >>> UTC_TZ = pytz.utc >>> EASTERN_TZ = pytz.timezone('America/New_York') >>> d1 =…
Chris B.
  • 85,731
  • 25
  • 98
  • 139
5
votes
1 answer

Changing timezone on an existing Django project

Like an idiot, I completely overlooked the timezone setting when I first built an application that collects datetime data. It wasn't an issue then because all I was doing was "time-since" style comparisons and ordering. Now I need to do full reports…
Oli
  • 235,628
  • 64
  • 220
  • 299
5
votes
2 answers

Checking if a datetime object in mongodb is in UTC format or not from python

In mongodb, a field called joining_date appears as "Sun Dec 19 2010 05:35:55 GMT+0000 (UTC)" This as you see is a UTC date . But the same field when accessed from pymongo appears as datetime.datetime(2010, 12, 19, 5, 35, 55, 286000) From python…
James
  • 51
  • 1
  • 2
5
votes
4 answers

How to check if date is in UTC format using pytz or datetime?

I'm using the pytz module to translate a date from America/Los_Angeles timezone to UTC using the code below: TZ = 'America/Los_Angeles' from = pytz.timezone(TZ) utc = from.localize(original_date).astimezone(pytz.utc) Now, I want to test if the UTC…
Jill
  • 53
  • 1
  • 1
  • 3
5
votes
1 answer

Set timezone without changing time - Python

Seemingly simple but I cannot get it to work. I have tried pytz.timezone('timezone').localize(dt.datetime().now()), dt.datetime.now().astimezone(pytz.timezone('timezone')) along with many other snippets, however they all create the a datetime object…
Fred Peters
  • 91
  • 1
  • 7
5
votes
2 answers

Module pytz: UTC decrease instead of increase

EDITED: I want to convert a UTC time in my country UTC (spain). I am using the module pytz to do the conversion but the result I am getting is UTC-1 rather than the UTC+1. This is my code: import datetime import pytz madrid =…
Dani LA
  • 107
  • 1
  • 7
5
votes
5 answers

Python How to Check if time is midnight and not display time if true

I'm modifying our pacific time zone filter to include a time option. I don't want the time component to be shown if midnight. The only import thus far we are using is dateutil.parser. Any pointers on best solution would be appreciated! Thanks. def…
Adrianopolis
  • 1,272
  • 1
  • 11
  • 15
5
votes
0 answers

Pytz not compiling correctly when using Pyinstaller

python 2.7.11 The script uses pytz, using Pyinstaller it was compiled into an executable. The .exe works fine from my computer; however when opened by someone else they encountered this error: Traceback : File "",…
Tero
  • 81
  • 4
5
votes
1 answer

How to append on a dataframe with timezone aware timestamp column?

I have a data frame with a timestamp column and a numeric column. I am able to append a new row to it if the timestamp column is timezone naive. df = pd.DataFrame([[1,2],[3,4]], columns=['timestamp',…
yadu
  • 63
  • 7
5
votes
1 answer

Django/python - dispelling confusion regarding dates and timezone-awareness

I've been working extensively with dates in python/django. In order to solve various use-cases I've been blindly trying a variety of different approaches until one of them worked, without learning the logic behind how the various functions work. Now…
Gershom Maes
  • 7,358
  • 2
  • 35
  • 55
5
votes
1 answer

How do I create a unix timestamp that doesn't adjust for localtime?

So I have datetime objects in UTC time and I want to convert them to UTC timestamps. The problem is, time.mktime makes adjustments for localtime. So here is some code: import os import pytz import time import datetime epoch =…
sheats
  • 33,062
  • 15
  • 45
  • 44
5
votes
2 answers

Assign timezone to a Python datetime

Assume that I have a timezone-less datetime object: import datetime import pytz fmt = "%Y-%m-%d %H:%M:%S %Z%z" dtUnaware = datetime.datetime(1979,2,20,6) print(dtUnaware.strftime(fmt)) This yields: 1979-02-20 06:00:00 So far, so good. Now, I…
Dror
  • 12,174
  • 21
  • 90
  • 160
5
votes
1 answer

Django asked me to install pytz and now my models won't validate Django

I was getting this error when testing out a project I just set up Exception Type: ImproperlyConfigured Exception Value: This query requires pytz, but it isn't installed. After a little googling I found that I was getting this because in my…
guribe94
  • 1,551
  • 3
  • 15
  • 29