utc to local time python

Solutions on MaxInterview for utc to local time python by the best coders in the world

showing results for - "utc to local time python"
Maëlle
02 Jan 2017
1# here are a few ways to convert time zone
2from datetime import datetime
3from dateutil import tz
4
5# METHOD 1: Hardcode zones:
6from_zone = tz.gettz('UTC')
7to_zone = tz.gettz('America/New_York')
8
9# METHOD 2: Auto-detect zones:
10from_zone = tz.tzutc()
11to_zone = tz.tzlocal()
12
13# utc = datetime.utcnow()
14utc = datetime.strptime('2011-01-21 02:37:21', '%Y-%m-%d %H:%M:%S')
15
16# Tell the datetime object that it's in UTC time zone since 
17# datetime objects are 'naive' by default
18utc = utc.replace(tzinfo=from_zone)
19
20# Convert time zone
21central = utc.astimezone(to_zone)
22
queries leading to this page
utc 2b2 in pythonconvert utc datetime to local time in pythonpython time utc converterutc to datetime pythonutc time to date pythonpython convert from local time to utcconvert utc to local time datetime pythonutc time to us time python convert convert local time to utc pythonconvert utc to datetime pythonutc specific time pythonpython convert from utc to local timepython convert utc to central timedatetime convert from utc to local pythonutc to local time pythonpython coverting utc time to local timepython utc to gps timepython datetime utc to local timepython convert utc to local pytzhow to convert utc to datetime in pythonconvert utc timestamp to local time pythonfrom utc to gps time pythonconvert utc time to local time pythonpython convert utc time to local timepython utc time to datetimepython convert utc to local timepython datetime utc to localpython utc to datetimeconvert a date utc to local pythonconvert utc to local time pytohnpython utc to localhow to convert dublin time to utc time in pythonpython utc to datetimeconvert utc time to local time passing timezone pythonpython utc to local timehow to convert utc datetime to local datetime in pythonutc time to datetime pythonconvert from utc to local time pythonpython utc to timhow to convert utc time to local time in pythonutc to local time converter pythonconvert utc to ist using python datetimepython convert utc time to locallocaltime to utc pythonconvert utc time to local time in pythonconvert time to utc time in pythonutc time pythonconvert utc to local time pythonutc covert to local time in pythonconvert utc time sec pythonconvert local time time to utc pythonchange utc time to local time pythonutc time to local time pythonutc local time ptyhonchange time to utc time in pythonpython time utc to localtime using local timezoneget utc time in pythonhow to convert current time to utc time in pythonpython change utc to local timepython time utc to localtimelocaltime to utc datetime pythnohow to convert utc time to cet pythonpython convert local time to utcpython datetime from utc to localconvert time to utc in pythonutc to local time python