JavaScript timestamp to Python datetime conversion

前端 未结 3 2066
滥情空心
滥情空心 2020-12-03 00:29

To get timestamp in JavaScript we use

var ts = new Date().getTime()

What is the proper way to convert it to a Python datetime

3条回答
  •  温柔的废话
    2020-12-03 01:04

    For others still getting an error: I had a similar issue but the unix timestamp was in microseconds, i.e. I had to divide the timestamp by 1000000 to get the correct result.

    dt = datetime.datetime.fromtimestamp(1502360499615921)
    

提交回复
热议问题