Skip to content

datetime.datetime.now() returns wrong time on Windows when env var TZ is set #124286

Open
@jjYBdx4IL

Description

@jjYBdx4IL

Bug report

Bug description:

Europe/Berlin is UTC+2 right now, not UTC+1

Works fine on Linux OSes (builds).

C:\Users\work>python
Python 3.12.6 (tags/v3.12.6:a4a2d2b, Sep  6 2024, 20:11:23) [MSC v.1940 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ['TZ'] = 'Europe/Berlin'
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2024, 9, 20, 12, 15, 24, 771320)
>>> datetime.datetime.now(tz=datetime.UTC)
datetime.datetime(2024, 9, 20, 11, 15, 45, 162005, tzinfo=datetime.timezone.utc)
>>>

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions