格林威治时间(GTM)转北京时间

需要模块:pytz(三方)和datetime

import pytz
import datetime

time = "Tue, 12 Jun 2012 14:03:10 GMT"
gmt = pytz.timezone('GMT')
eastern = pytz.timezone('Asia/Chongqing')
date = datetime.datetime.strptime(time, '%a, %d %b %Y %H:%M:%S GMT')
# 2012-06-12 14:03:10
print(date)
dategmt = gmt.localize(date)
# 2012-06-12 14:03:10+00:00
print(dategmt)
dateeastern = dategmt.astimezone(eastern)
# 2012-06-12 22:03:10+08:00
print(dateeastern)
posted @ 2018-08-13 13:56  007少侠  阅读(933)  评论(0编辑  收藏  举报
友情链接:便宜vps(CN2GIA线路)
站长统计: