search

Home  >  Q&A  >  body text

python - 时间戳转化正常时间

慕课网模拟登入时候,有个验证码,貌似是用时间戳拼接的。
登入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

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

PHPzPHPz2898 days ago349

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-04-18 10:05:52

    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

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 10:05:52

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

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:05:52

    This is the timestamp of js, divided by 1000

    reply
    0
  • Cancelreply