#as an aware datetime
from datetime import datetime, timezone
utc_dt = datetime.now(timezone.utc) # UTC time
dt = utc_dt.astimezone() # local time
#or from pytz database
import pytz
tz = pytz.timezone('Europe/Berlin')
berlin_now = datetime.now(tz)
import datetime
import pytz
my_date = datetime.datetime.now(pytz.timezone('US/Pacific'))
import datetime
import pytz
d = datetime.datetime.now()
timezone = pytz.timezone("America/Los_Angeles")
# List of Time Zones: https://gist.github.com/heyalexej/8bf688fd67d7199be4a1682b3eec7568
d_aware = timezone.localize(d)
d_aware.tzinfo
# One Liner
timezone.localize(datetime.datetime.now())
# Timestamp to Datetime with timezone
datetime.fromtimestamp(3456789, timezone)
from datetime import timezone
ts = now.strftime("%Y-%m-%d %H:%M:%S%z")
from time import gmtime, strftime
print(strftime("%z", gmtime()))
from datetime import datetime
import pytz
local = datetime.now()
print("Local:", local.strftime("%m/%d/%Y, %H:%M:%S"))
tz_NY = pytz.timezone('America/New_York')
datetime_NY = datetime.now(tz_NY)
print("NY:", datetime_NY.strftime("%m/%d/%Y, %H:%M:%S"))
tz_London = pytz.timezone('Europe/London')
datetime_London = datetime.now(tz_London)
print("London:", datetime_London.strftime("%m/%d/%Y, %H:%M:%S"))