标签:
?
时间:
tickets
时间元组
格式化的时间
日历
import time tickets = time.time() print tickets print time.localtime() #本地时间元组 print time.gmtime() #UTC时间元组 print time.asctime(time.localtime()) ? import calendar print calendar.month(2015,8) |
?
?
CPU时钟:clock
睡眠:sleep
创建时间:mktime
#clock & sleep import time def procedure(): time.sleep(0.5) ? t0 = time.clock() procedure() print time.clock() - t0 #mktime t = (2009, 2, 17, 17, 3, 38, 1, 48, 0) secs = time.mktime(t) print "time.mktime(t) : %f" % secs print time.localtime(secs) |
?
datetime:类似C#的DateTime
import datetime dt = datetime.datetime(2015,8,11,10,31,55) print dt print dt.hour print dt.second ? delta = datetime.timedelta(hours=5) print dt + delta print dt - delta ? ? from datetime import datetime format = "output-%Y-%m-%d-%H%M%S.txt" str = "output-1997-12-23-030000.txt" t = datetime.strptime(str, format) ? from datetime import * print datetime.now() print date.today() |
标签:
原文地址:http://www.cnblogs.com/pengzhen/p/4720344.html