2 weixin 39218943 weixin_39218943 于 2017.09.01 11:16 提问

python脚本怎么修改utc时间为自己需要的

怎么用一个python脚本将一个utc时间如1503936000,需要根据系统时间取前一天00:00:00转换为utc时间,求详细代码

1个回答

oyljerry
oyljerry   Ds   Rxr 2017.09.01 13:42
已采纳
 In [1]: import datetime

In [2]: a = datetime.datetime.fromtimestamp(1503936000)

In [3]: a
Out[3]: datetime.datetime(2017, 8, 29, 0, 0)


In [5]: yesterday = a - datetime.timedelta(days=1)

In [6]: yesterday
Out[6]: datetime.datetime(2017, 8, 28, 0, 0)

In [7]: import time

In [8]: b = time.mktime(yesterday.timetuple())*1e3 + yesterday.microsecond/1e3

In [9]: b
Out[9]: 1503849600000.0
Csdn user default icon
上传中...
上传图片
插入图片