Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

utc to local time python

# here are a few ways to convert time zone
from datetime import datetime
from dateutil import tz

# METHOD 1: Hardcode zones:
from_zone = tz.gettz('UTC')
to_zone = tz.gettz('America/New_York')

# METHOD 2: Auto-detect zones:
from_zone = tz.tzutc()
to_zone = tz.tzlocal()

# utc = datetime.utcnow()
utc = datetime.strptime('2011-01-21 02:37:21', '%Y-%m-%d %H:%M:%S')

# Tell the datetime object that it's in UTC time zone since 
# datetime objects are 'naive' by default
utc = utc.replace(tzinfo=from_zone)

# Convert time zone
central = utc.astimezone(to_zone)
Comment

PREVIOUS NEXT
Code Example
Python :: web scraping linkedin profiles python jupyter 
Python :: python teilen ohne rest 
Python :: how to obtain the content of brackets 
Python :: print nested list in new lines 
Python :: how does sns boxplot determine outliers 
Python :: how to convert 24 hours to 12 hours in python 
Python :: how to open a website with selenium python 
Python :: selenium text returns empty string python 
Python :: python split dict into chunks 
Python :: delete row from dataframe python 
Python :: python scatterplot 
Python :: list of files in python 
Python :: python endswith list 
Python :: vs code run python in terminal invalid syntax 
Python :: remove warnings from jupter notebook 
Python :: python check if all dictionary values are False 
Python :: django gunicorn static file not found 
Python :: kivy changing screen in python 
Python :: how to check if a number is odd python 
Python :: how to access all the elements of a matrix in python using for loop 
Python :: gpu training tensorflow 
Python :: Plotting keras model trainning history 
Python :: how to move your cursor using python 
Python :: python intersection of two lists 
Python :: python every other goes to a list 
Python :: python little endian to big endian 
Python :: decision tree gridsearchcv 
Python :: how to run single loop iterations on same time in python 
Python :: append to csv python 
Python :: simulated annealing python 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =