一、时间
import time
res = time.time()
print(res)
res2 = time.localtime(1562639903.607295)
print(res2)
tm_year:年
tm_mon:月
tm_mday:日
tm_hour:小时
tm_min:分钟
tm_sec:秒
tm_wday:星期几
tm_yday:一年中第几天
tm_isdst:是否是夏令时
res3 = time.ctime(1562639903.607295)
print(res3)
结果 'Tue Jul 9 10:38:23 2019'
t_tup = time.localtime()
res4 = time.asctime(t_tup)
print(res4)
time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
tt = time.strptime("2016-03-20 11:45:39", "%Y-%m-%d %H:%M:%S")
将时间元组转换成 时间戳
time.mktime(tt)
获取当前cpu时间
time.clock()
二、日期
import datetime
res2 = datetime.datetime.now()
res3 = datetime.datetime.today()
print(res2)
print(res3)
2019-07-09 11:29:48.064887
2019-07-09 11:29:48.064887
print(res2.year)
print(res2.month)
print(res2.day)
print(res2.hour)
print(res2.minute)
print(res2.second)
t = datatime.datatime.now()
res = t + datatime.timedelta(days=2)
start = datetime.datetime(2019,7,9,11,47,50)
end = datetime.datetime(2019,7,11,11,47,50)
delta = end-start
print(delta)
print(delta.total_seconds())
三、日历
import calendar
res = calendar.month(2019,6)
print(res)
结果
"""
June 2019
Mo Tu We Th Fr Sa Su
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
"""