pythonmokuai/ target=_blank class=infotextkey>python模块之time模块,主要功能是获取时钟时间和cpu处理器运行的时间,以及时间格式的转换。
time.time()返回当前系统时间距离1970-01-01 00:00多少秒
time.clock()返回该程序到目前为止cpu运行的时间
time.sleep()使程序停止的秒数(此时间不记录cpu运行时间)
time.localtime()转换秒显示时间为一个tuple,默认是当前时间
time.ctime()与time.localtime()类似,只不过会转换时间为一个字符串,默认也是当前时间
time.mkdtime()与time.localtime()正好相反
time.strftime()格式化输出时间格式
>>> time.strftime('%Y-%M-%d %H:%m:%S',time.localtime())
'2012-24-30 21:12:27'
%% a literal %
%a locale's abbreviated weekday name (e.g., Sun)
%A locale's full weekday name (e.g., Sunday)
%b locale's abbreviated month name (e.g., Jan)
%B locale's full month name (e.g., January)
%c locale's date and time (e.g., Thu Mar 3 23:05:25 2005)
%C century; like %Y, except omit last two digits (e.g., 20)
%d day of month (e.g., 01)
%D date; same as %m/%d/%y
%e day of month, space padded; same as %_d
%F full date; same as %Y-%m-%d
%g last two digits of year of ISO week number (see %G)
%G year of ISO week number (see %V); normally useful only with %V
%h same as %b
%H hour (00..23)
%I hour (01..12)
%j day of year (001..366)
%k hour, space padded ( 0..23); same as %_H
%l hour, space padded ( 1..12); same as %_I
%m month (01..12)
%M minute (00..59)
%n a newline
%p locale's equivalent of either AM or PM; blank if not known
%P like %p, but lower case
%r locale
time.strptime()将时间转换成元组模式