yanglgzh 发表于 2018-8-9 13:16:02

python - time

importtime  
import calendar
  
#打印时间戳
  
print (time.time())
  
#结果为: 1483808872.8317335
  
#-----------------将时间戳格式化---------------------
  
print(time.asctime(time.localtime(time.time())))
  
#结果为:Sun Jan8 01:07:52 2017
  
#-----------------使用strftime()方法格式化输出时间-----------------
  
print (time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
  
#输出结果为:2017-01-08 01:11:37
  
#-----------------将Sun Jan8 01:33:49 2017 转换为时间戳-----------------
  
a=time.asctime(time.localtime(time.time()))
  
print (time.mktime(time.strptime(a,'%a %b %d %H:%M:%S %Y')))
  
print (time.mktime(time.strptime((time.asctime(time.localtime(time.time()))),'%a %b %d %H:%M:%S %Y')))
  
#输出结果:1483810429.0
  
#打印日历
  
print (cal + "Clock: " + (time.asctime(time.localtime(time.time()))).split())
  
#结果为
  

  
    January 2017
  
Mo Tu We Th Fr Sa Su
  
                   1
  
2345678
  
9 10 11 12 13 14 15
  
16 17 18 19 20 21 22
  
23 24 25 26 27 28 29
  
30 31
  
Clock: 01:42:00
页: [1]
查看完整版本: python - time