【发布时间】:2018-12-23 08:40:52
【问题描述】:
所以我有以下代码:
import pytz
from datetime import datetime
tz = pytz.timezone('Asia/Singapore')
original_time = tz.localize(datetime.now())
original_epoch = original_time.timestamp()
converted_dt = tz.localize(datetime.utcfromtimestamp(original_epoch))
converted_epoch = converted_dt.timestamp()
print('{}\t\t{}'.format(original_time, original_epoch))
print('{}\t\t{}'.format(converted_dt, converted_epoch))
然后吐出来
# Original Time Original Epoch
2018-07-16 02:17:41.583510+08:00 1531678661.58351
2018-07-15 18:17:41.583510+08:00 1531649861.58351
# Converted Time Converted Epoch
这是一个 Python 错误还是我只是遗漏了什么?无论哪种方式,我怎样才能将日期时间转换为纪元并返回,并确信我回到了正确的时间?
【问题讨论】:
标签: python python-3.x python-3.6 pytz