Reputation: 2503
I would like to call current datetime.now() with GMT +0 (UK) time zone. My workstation is in other timezone.
How to do it?
Upvotes: 2
Views: 8615
Reputation: 1153
Try this:
Before Python 3.6 you can use pytz (external package)
from datetime import datetime
from pytz import timezone
print(datetime.now(timezone('Europe/London')))
Update according @WolfgangKuehn comment
Starting from Python 3.6 you can use zoneinfo via standard library (>=3.9) or backport instead of pytz
from datetime import datetime
from zoneinfo import ZoneInfo
print(datetime.now(ZoneInfo('Europe/London')))
Upvotes: 6
Reputation: 594
from datetime import datetime, timezone
print(datetime.now(timezone.utc))
Upvotes: 1