Timezone in python
import pytm, datetime
Print all time zone with the help of pytm
pytz.all_timezones
or
for tz in pytz.all_timezones:
print (tz)
UTC Date Time
date_time_utc = datetime.datetime.utcnow()
Create timezone object
america_st_johns = pytz.timezone('America/St_Johns')
Convert UTC to other TimeZone
local_dt = date_time_utc.replace(tzinfo=pytz.utc).astimezone(america_st_johns)
date_time_utc = datetime.datetime.utcnow()
Create timezone object
america_st_johns = pytz.timezone('America/St_Johns')
Convert UTC to other TimeZone
local_dt = date_time_utc.replace(tzinfo=pytz.utc).astimezone(america_st_johns)
Output # datetime.datetime(2019, 8, 20, 13, 49, 18, 905051, tzinfo=<DstTzInfo 'America/St_Johns' NDT-1 day, 21:30:00 DST>)
Remove tzinfo from this object
date_time.replace(tzinfo = None)
Output # datetime.datetime(2019, 8, 20, 13, 51, 38, 177591)
Comments
Post a Comment