datetime是Python处理日期和时间的标准库。

 1 from datetime import datetime
 2 
 3 # 获取当前时间
 4 now = datetime.now()
 5 print(now)
 6 # 结果:2018-03-29 11:25:28.103611
 7 
 8 # 获取指定日期和时间
 9 t = datetime(2017, 3, 7, 13, 32, 33)
10 print(t)
11 # 结果:2017-03-07 13:32:33
12 
13 # 将时间转化为时间戳
14 now = datetime.now()
15 print(now.timestamp())
16 # 结果:1522294205.278572
17 
18 # 将时间戳转化为可读时间
19 t = 1522294205.278572
20 print(datetime.fromtimestamp(t))
21 # 结果:2018-03-29 11:30:05.278572

 

相关文章:

  • 2022-12-23
  • 2021-11-26
  • 2021-08-15
  • 2021-10-29
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
猜你喜欢
  • 2021-07-02
  • 2021-12-13
  • 2021-06-15
  • 2021-04-11
相关资源
相似解决方案