首页 > 代码库 > Python的time模块
Python的time模块
time模块下只有若干个方法,没有类,所以直接用time.方法即可
1.time() -- return current time in seconds since the Epoch as a float
print time.time() 返回日期的秒数 1492351508.72
2.clock() -- return CPU time since process start as a float
输出CPU时间
3.sleep() -- delay for a number of seconds given as a float
4.gmtime() -- convert seconds since Epoch to UTC tuple
5.localtime() -- convert seconds since Epoch to local time tuple
把时间戳转为time.time_struct格式的时间数组
print time.localtime(time.time())
time.struct_time(tm_year=2017, tm_mon=4, tm_mday=16, tm_hour=22, tm_min=14, tm_sec=57, tm_wday=6, tm_yday=106, tm_isdst=0)
6.asctime() -- convert time tuple to string
把时间数组转换为字符串
print time.asctime(time.localtime(time.time()))
Sun Apr 16 22:27:11 2017
7.ctime() -- convert time in seconds to string
把以秒表示的时间转为字符串
print time.ctime(time.time())
Sun Apr 16 22:27:57 2017
8.mktime() -- convert local time tuple to seconds since Epoch
把时间数组转为秒表示
print time.mktime(time.localtime(time.time()))
1492352997.0
9.strftime() -- convert time tuple to string according to format specification
10.strptime() -- parse string to time tuple according to format specification
11.tzset() -- change the local timezone
Python的time模块
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。