68 questions
4
votes
1
answer
136
views
Python datetime and timedelta behaviour over Daylight savings time change
I encountered this behaviour and I figured I would ask the correct way to go about it.
Here is a toy example:
pre_timechange = datetime.datetime(2025, 11, 2, 1, 59, 9, tzinfo=zoneinfo.ZoneInfo(key='...
2
votes
1
answer
55
views
Python: Converting string in NZ summer time to UTC gives wrong result
I am creating a simple script where I need to convert
strings with date and time given in NZ time to corresponding
UTC time.
The time series are done in NZ summer (Dec-Feb) and hence the
NZ time is 13 ...
0
votes
1
answer
99
views
Get the canonical timezone name of a backward linked timezone in python?
As title said, I'm looking for a simple way to get the canonical name of a timezone when providing a timezone name.
For example Asia/Calcutta is the backward liked name of Asia/Kolkata.
I'd expect ...
2
votes
2
answers
82
views
How do I determine whether a ZoneInfo is an alias?
I am having trouble identifying whether a ZoneInfo is built with an alias:
> a = ZoneInfo('Atlantic/Faeroe')
> b = ZoneInfo('Atlantic/Faroe')
> a == b
False
It seems like these ZoneInfos are ...
2
votes
2
answers
79
views
Convert the same local time to UTC on different dates, respecting the local DST status
I have several local time points:
import datetime
from zoneinfo import ZoneInfo as zi
wmr = datetime.time(hour=12, tzinfo=zi("GMT"))
ecb = datetime.time(hour=14, minute=15, tzinfo=zi("...
0
votes
1
answer
135
views
How to get the time zone from datetime with zoneinfo libraries in Python?
I have a code where I get date and time of different parts of the world with the datetime and zoneinfo libraries in Python. I am able to extract the dates and hourse separately in day, month, year, ...
0
votes
1
answer
79
views
Assigning a var to ZoneInfo("US/Eastern") at the start and re-using it in perpetuity without daylight saving issues?
I use the same timezone repeatedly in my python code when creating datetime objects.
So far I've just been creating a new ZoneInfo object each time, similar to this:
dt = datetime.now(tz=ZoneInfo(&...
1
vote
1
answer
417
views
zoneinfo is missing timezone names that pytz has
I am comparing the timezone names that pytz and zoneinfo support because I would like to transition to zoneinfo from pytz.
It seems that zoneinfo lacks a lot of timezones:
>>> import pytz
>...
1
vote
1
answer
2k
views
Why are python timezone.utc and ZoneInfo("UTC") not equivalent tzinfo objects? How to check they are the same TZ?
Why are these not equal?
>>> from datetime import datetime
>>> from datetime import timedelta
>>> from datetime import timezone
>>> from zoneinfo import ZoneInfo
&...
1
vote
2
answers
306
views
Using Pandas 2.0 with Python 3.8 without Zoneinfo
I am running some code using Python 3.8. As it is for a scientific experiment that has already been run in this configuration before, I cannot currently update to a newer version of Python. I am using ...
3
votes
1
answer
681
views
Create TZ string from Python ZoneInfo
I can easily get a ZoneInfo object for the time zone of my choice:
import zoneinfo
ct = zoneinfo.ZoneInfo('America/Chicago')
I need to create a TZ environment variable for an embedded system that ...
0
votes
2
answers
127
views
Why is zoneinfo shifting DST by 2 hours instead of 1?
I need to make sure that when a naive datetime is made aware the DST rules are applied correctly. What I find here is just odd to me.
Somehow zoneinfo decides to increment the DST transition for ...
-2
votes
1
answer
1k
views
Is Linux /usr/share/zoneinfo/ platform agnostic? [closed]
My embedded Linux program needs to convert UTC time to local time for a report saved in a text file. The most obvious way to do this is to use the API function strftime().
However... on my system, the ...
1
vote
1
answer
140
views
UTC offset not correct using tz_localize and ZoneInfo
I have a pd.DatetimeIndex object in local time without UTC offsets. I am now trying to localize this object using tz_localize and a ZoneInfo object so that it contains UTC offset information, i.e. ...
0
votes
0
answers
249
views
Need to convert a datetime.tzinfo *region* to a ZoneInfo region
I'm writing a calendar application, and I have been trying to track down why canceled / rescheduled calendar entries keep appearing on my calendar. I traced the problem to a time zone issue with ...
3
votes
1
answer
2k
views
Python pytz, zoneinfo and daylight savings time
I am currently attempting to migrate a code base from using pytz to using Python's zoneinfo library. I've run into an issue with how zoneinfo handles daylight saving time transitions when compared to ...
15
votes
1
answer
9k
views
Is `pytz` deprecated now or in the future in Python?
pytz is used in the Django version: <=3.2 doc Selecting the current time zone as shown below:
import pytz # Here
from django.utils import timezone
class TimezoneMiddleware:
def __init__(self, ...
2
votes
0
answers
88
views
Why do pandas and python differ in how they convert a datetime to America/Boise?
Here's an example:
import pandas as pd
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
string = '2038-04-01 09:00:00.000000'
dt = datetime.fromisoformat(string)
dt = dt....
0
votes
0
answers
157
views
How do I convert a particular time to a UTC time in python?
Currently working on a project where I need to manipulate a particular store's opening and closing times to UTC in Python. The opening and closing times are date independent.
For instance , I have a ...
4
votes
0
answers
4k
views
pytz and ZoneInfo return different times for same functions. What's wrong with my implementation? [duplicate]
I am trying to add a timezone to a time without timezone. However, using 2 libraries gives 2 different results:
from datetime import datetime
import pytz
from zoneinfo import ZoneInfo
cur = datetime....
0
votes
0
answers
250
views
Comparing pytz.timezone instances
I need to compare pytz.timezones for equality, and the behavior I'm observing is quite unintuitive.
I've read a lot about Python time zones, pytz, zoneinfo, LMT, etc., both on SO and generally on the ...
3
votes
1
answer
636
views
Localize time zone based on column in pandas
I am trying to assign a timezone to a datetime column, based on another column containing the time zone.
Example data:
DATETIME VALUE TIME_ZONE
0 2021-05-01 00:00:00 1....
1
vote
3
answers
5k
views
American time zones like CT, give error: ZoneInfoNotFoundError: 'No time zone found with key CT'
Python 3.9 introduced the zoneinfo module:
The zoneinfo module provides a concrete time zone implementation to support the IANA time zone database as originally specified in PEP 615. By default, ...
2
votes
2
answers
708
views
Using zoneinfo with pandas.date_range
I am trying to use zoneinfo instead of pytz. I am running into a problem using zoneinfo to initiate dates and passing it on to pd.date_range.
Below is an example of doing the exact same thing with ...
1
vote
1
answer
1k
views
How does ZoneInfo handle DST in the distant future?
I'm trying to understand how the zoneinfo module figures out daylight savings time transitions in the distant future while it seems that dateutil and pytz both give up on daylight savings time ...
4
votes
2
answers
9k
views
Why does ZoneInfo("UTC") do different time conversions from timezone.utc?
I was trying to convert a datetime from one timezone to another. I'm in the process of updating our Python codebase to stop relying on utilities we don't need anymore. In particular, I'm deprecating ...
1
vote
1
answer
724
views
DRF TimeZoneField: not JSON serializable error
I have django model:
from django.db import models
from timezone_field import TimeZoneField
class Client(models.Model):
time_zone = TimeZoneField(choices_display='WITH_GMT_OFFSET')
And APIView ...
0
votes
1
answer
407
views
exchangelib Library failure in Python with PyInstaller
I am writing an application that will connect to the Exchange Server and send an email to a recipient on a scheduled basis. This application depends upon a successful import exchanglib.
I'm able to ...
0
votes
1
answer
524
views
How to get latitude and longitude for a timezon database name (tzinfo)?
My web app has a need to very roughly locate the user in order to calculate sunset and sunrise times.
Since geolocation features necessarily ask the user for permission, I'm brainstorming other ways ...
2
votes
2
answers
786
views
How to get timezone rules version used by datetime?
In John Skeet's blog post about handling timezone information when storing future datetimes, he suggests storing the version of timezone rules in the database along with the local time and timezone id....
0
votes
0
answers
927
views
Python: ZoneInfo.astimezone() not making sense
I am migrating away from pytz (the fastest footgun in the west), to ZoneInfo.
I am doing a test with timezone Africa/Johannesburg, which is GMT+2 (Note: GMT = UTC). I expect the following to yield the ...
4
votes
2
answers
4k
views
Convert an aware datetime's timezone to UTC with zoneinfo (migration away from pytz)
I am using Python 3.8, so I am using https://pypi.org/project/backports.zoneinfo/ to get zoneinfo. Django is deprecating the use of pytz so I am performing the change from pytz to zoneinfo
With pytz ...
2
votes
2
answers
1k
views
Time conversion from UTC to Europe/Warsaw
I'm trying to convert UTC time to Europe/Warsaw time. Warsaw time is now UTC + 2 hours. I don't know why I get result with time 30 minutes eariler. I'm parsing date from string similar to: 7:27:02 AM ...
-1
votes
2
answers
215
views
Timezone conversion mysql funtion to c# [duplicate]
How to convert convert_tz() in mysql to a c# function
2
votes
1
answer
319
views
How can we find possible time zone names corresponding to a time zone abbreviation?
Given a time zone abbreviation, is there a way to get a list of possible time zones?
Like IST could mean one of the following:
Asia/Kolkata (India)
Asia/Tel_Aviv (Israel)
Europe/Dublin (Ireland)
...
2
votes
2
answers
1k
views
zoneinfo: what are the new right and posix zone-name prefixes?
The most recent zoneinfo database, as maintained by the Internet Assigned Numbers Authority, holds two new prefixes, 'posix' and 'right'. For example where there used to be just Asia/Kolkata the new ...
4
votes
3
answers
3k
views
exchangelib and pyinstaller - zoneinfo - tzdata - UTC issue
In my python project, I'm using exchangelib and I needed to create an exe file.
Using pyinstaller --onefile I had UTC errors (in general tzdata)-
"No timzone in key UTC".
Simplifying all and ...
0
votes
2
answers
232
views
Datetime with timezone
As far as I understood ZoneInfo in python 3.9 fixes the issue of "The year of 2038" problem with DST time issue. But I can see that the timedelta is wrong. Below it should have been 2 hours, ...
5
votes
1
answer
1k
views
Python 3.9: Construct DST valid timestamp using standard library
I would like to contruct DST-valid timestamps only using the standard library in Python 3.9 and was hoping this was possible with this version.In my timezone "Europe/Berlin", the DST ...
2
votes
2
answers
909
views
cockroach DB issue to start : Fail to initialize the node: unable to load named timezone
cockroach DB issue to start : Fail to initialize the node: unable to load named timezone.
I downloaded the zoneinfo.zip and unziped and configured the environment variable ZONEINFO and given into the ...
13
votes
3
answers
18k
views
Get local time zone name on Windows (Python 3.9 zoneinfo)
Checking out the zoneinfo module in Python 3.9, I was wondering if it also offers a convenient option to retrieve the local time zone (OS setting) on Windows.
On GNU/Linux, you can do
from datetime ...
3
votes
1
answer
6k
views
mysql_tzinfo_to_sql - updating the timezone tables after you already loaded them and other questions
I just used mysql_tzinfo_to_sql to load the zoneinfo database into mysql. They all imported fine.
[root@db ~]# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql mysql
I have some questions that I can'...
0
votes
1
answer
158
views
TZ Database on Debian Stable for Casablanca ignores the permanent change to DST and Adds an offset of 1
I am on a Debian Stable 9 (stretch), the newly updated TZ database for Africa/Casablanca Table currently states isdst=0 and an offset from UTC of +01.
From the DST in Morocco Wiki page
https://en....
2
votes
1
answer
1k
views
Timezone is wrong in database
I have made a date with the CURRENT_TIMESTAMP function in phpmyadmin. And the output value of the hours is wrong by 1hour. I have tried changing it in mysql using the
SET TIME_ZONE = '+01:00';
...
3
votes
1
answer
2k
views
Go doesn't find /usr/share/zoneinfo in docker container
In a Go program I call time.LoadLocation("Europe/Berlin") and it returns an error saying open /usr/local/go/lib/time/zoneinfo.zip: no such file or directory, even though in the container (running ...
-2
votes
1
answer
605
views
How to set half hour and 45-minute time zones without worrying about DST changes in Linux?
Currently I am setting time zone GMT+5 on my Linux CentOS 7 machine by linking /etc/localtime to /usr/share/zoneinfo/Etc/GMT-5.
I want to create a zone info file for example /usr/share/zoneinfo/Etc/...
10
votes
1
answer
3k
views
where are the leap seconds in javascript?
When I use
a custom zoneinfo file for TAI or /usr/share/zoneinfo-leaps and
a modified NTP client (currently it just adds 27 seconds; and waits for a time stamp that is about 1 second off)
on my ...
3
votes
1
answer
2k
views
Detect if ZONEINFO fails in Go
In Go, you can specify a specific zoneinfo.zip file to be used by adding a ZONEINFO environment variable that points to the specific file you'd like to use for time zone information. This is great as ...
0
votes
1
answer
7k
views
Unable to change the timezone of Mysql server
We have timezone set to IST (Indian Standard Time) to begin with -
mysql> show global variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+-...
7
votes
3
answers
11k
views
How can i convert time zone string to the TimeZone Object in java?
I have several time zone strings in UTC format, such as "UTC+08:00", "UTC-05:00", the question is how can i convert these utc format strings to the java.util.TimeZone in Java?
I ...