Python中的time函数的用法


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())

执行结果:

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM