Skip to content

Instantly share code, notes, and snippets.

@lbj96347
Created September 16, 2013 09:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbj96347/6578412 to your computer and use it in GitHub Desktop.
Save lbj96347/6578412 to your computer and use it in GitHub Desktop.
Use Python to change UTC time to Localtime.利用Python将国际标准时间改为本地时间
from dateutil import tz
from datetime import datetime
# UTC Zone
from_zone = tz.gettz('UTC')
# China Zone
to_zone = tz.gettz('Asia/Shanghai')
utc = datetime.utcnow()
# Tell the datetime object that it's in UTC time zone
utc = utc.replace(tzinfo=from_zone)
# Convert time zone
local = utc.astimezone(to_zone)
print datetime.strftime(local, "%Y-%m-%d %H:%M:%S")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment