Python将时间戳转换为日期
使用python 2.7,我有timestamms ex:Python将时间戳转换为日期,python,date,timestamp,Python,Date,Timestamp,使用python 2.7,我有timestamms ex:timestamms 1478001612891 我想把它转换成日期格式 我尝试了datetime.fromtimestamp(int('1478013706323')) 但是你会得到这个错误 Traceback (most recent call last): File "<interactive input>", line 1, in <module> ValueError: timestamp out o
timestamms 1478001612891
我想把它转换成日期格式
我尝试了datetime.fromtimestamp(int('1478013706323'))
但是你会得到这个错误
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
ValueError: timestamp out of range for platform localtime()/gmtime() function
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ValueError:platform localtime()/gmtime()函数的时间戳超出范围
日期时间。fromtimestamp要求以秒为单位输入。将数字除以1000.0
,然后再传入
(从规范中:
datetime.fromtimestamp(timestamp)
将返回与POSIX时间戳相对应的本地日期,例如通过time.time()返回的本地日期。time.time()
将以秒为单位以浮点数的形式返回历元后的时间
)好,这样就可以了。但这些数字代表什么呢?datetime.datetime(2016,11,1,11,21,46)从文档中,参数是年,月,日,小时=0,分钟=0,秒=0,微秒=0,tzinfo=None
。非常感谢,我会在几分钟内接受你的答案!