Created
September 16, 2013 09:24
-
-
Save lbj96347/6578412 to your computer and use it in GitHub Desktop.
Use Python to change UTC time to Localtime.利用Python将国际标准时间改为本地时间
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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