Nerdy Drunk

Drunk on technology

User Tools

Site Tools


python:time_zones

Table of Contents

Python Time Zones

Code

from datetime import datetime, timezone
from dateutil import tz

tz_local = tz.gettz('America/Chicago')
date_now = datetime.now(timezone.utc)

print('  UTC:', date_now)
print('Local:', date_now.astimezone(tz_local))

Output

  UTC: 2021-04-07 19:56:56.466314+00:00
Local: 2021-04-07 14:56:56.466314-05:00
python/time_zones.txt · Last modified: 2022/07/21 10:41 by 127.0.0.1