fengzhilaoling

Python中 time time()返回时当前时间的时间戳(1970纪元后经过的浮点秒数) 

 

time()方法语法:

  time.time()

 

实际案例:

# coding: UTF-8

import time  

print("time.time():%f" % time.time())

执行结果:

  

 

 

time.localtime() 返回代表当地具体时间,年、月、日、时、分、秒、周几、一年中的第几天、是否是夏令时等信息。

localtime()方法语法:

  time.localtime([参数,时间戳浮点数])

实际案例:

# coding: UTF-8

import time  

print(time.localtime())  #当参数为空时默认为当前时间

a = 1529907030.229088
print(time.localtime(a)) #指定参数返回时间

#获取单独的年月日信息
t = time.localtime()
print("当前年份:%s  当前月份:%s  当前日期:%s" % (t.tm_year,t.tm_mon,t.tm_mday))

执行结果:

  

 

 

 

time.asctime():返回已经格式化的时间字符串。 参数必须是表示时间的struct_time元组,为空时将time.localtime()作为参数

asctime()方法语法:

  time.localtime()

 

实际案例:

# coding: UTF-8

import time  

print(time.asctime())

执行结果:

  

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2021-09-01
  • 2021-11-29
  • 2022-01-07
  • 2022-01-07
  • 2021-09-14
猜你喜欢
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2021-11-23
  • 2021-12-22
相关资源
相似解决方案