没有在python中快速弄清楚如何将时间ISO 8601
STRING(带MS)转换为13位TIMESTAMP
(MS),反之亦然。有人可能会对此有所了解吗?
'2017-11-01T08:11:44.040Z' to '1509523904040'
'1509523904040' to '2017-11-01T08:11:44.040Z'
答案 0 :(得分:0)
这应该有所帮助。
import datetime
s = '2017-11-01T08:11:44.040Z'
#Convert datetime to epoch.
value = (datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%S.%fZ") - datetime.datetime(1970,1,1)).total_seconds()
print( value )
#Convert epoch to datetime.
print( datetime.datetime.fromtimestamp(value) )
<强>输出:强>
1509523904.04
2017-11-01 13:41:44.040000