Python Utc时间转北京时间
import time from datetime import datetime from datetime import timedelta time_stamp = 1525848792 loc_time = time.localtime(time_stamp) time1 = time.strftime("%Y-%m-%d %H:%M:%S",loc_time) utc_time = datetime.utcfromtimestamp(time_stamp) time2 = utc_time + timedelta(hours=8) print(time1) print(time2)
由于我们是在东八区,utc时间是在本初子午线,也就是在我们西边八个时区,所以要加上八个小时。结果如下:
2018-05-09 14:53:12 2018-05-09 14:53:12 [Finished in 0.1s]
只留作自己笔记小结。
本文来自博客园, 作者:Star-Hitian, 转载请注明原文链接:https://www.cnblogs.com/Star-Haitian/articles/9306072.html