https://www.cnblogs.com/chen55555/p/11653935.html

python 毫秒时间戳转日期

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

import time

import datetime

 

timestamp = 1570774556514

 

# 转换成localtime

time_local = time.localtime(timestamp/1000)

# 转换成新的时间格式(精确到秒)

dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local)

print(dt)   # 2019-10-11 14:15:56

 

= datetime.datetime.fromtimestamp(timestamp/1000)

# 精确到毫秒

str1 = d.strftime("%Y-%m-%d %H:%M:%S.%f")

print(str1)  # 2019-10-11 14:15:56.514000

  

相关文章:

  • 2021-12-30
  • 2021-12-30
  • 2021-12-30
猜你喜欢
  • 2021-12-26
  • 2021-12-18
  • 2022-12-23
  • 2021-12-30
  • 2021-11-22
  • 2021-12-03
相关资源
相似解决方案