python - 时间戳转化正常时间
PHPz
PHPz 2017-04-18 10:03:52
0
3
342

慕课网模拟登入时候,有个验证码,貌似是用时间戳拼接的。
登入url:http://www.imooc.com/user/new...

t=1481443995340 像是正常的时间戳乘于1000后的结果

但我用python还原这个时间,怎么都对不上

In[26]: print time.localtime(14814439953.40)
time.struct_time(tm_year=2439, tm_mon=6, tm_mday=14, tm_hour=18, tm_min=12, tm_sec=33, tm_wday=1, tm_yday=165, tm_isdst=0)

格式化下:

In[27]: print time.strftime('%Y%m%d %H:%M:%S', time.localtime(14814439953.40));
24390614 18:12:33

这是为咋的?
是时间戳再处理过还是还原的不对,还是不是时间戳来着的?

PHPz
PHPz

学习是最好的投资!

reply all(3)
刘奇

means that it is the timestamp of js. The timestamp of js is at the millisecond level, which is not at the same level as that of python, so this operation is fine:

>>> from datetime import datetime
>>> timestamp='1481443995340'
>>> print datetime.fromtimestamp(float(timestamp[:-3])).strftime('%Y-%m-%d %H:%M:%S')
'2016-12-11 16:13:15'

You can see it’s exactly today’s time

左手右手慢动作

1481443995340 This is obviously not a timestamp. The format is wrong

伊谢尔伦

This is the timestamp of js, divided by 1000

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template