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