争取写完,持续更新
import sys
print(sys.pltfrom)
import time
now=time.time()
print(now)
1611303060.773287
import time
now=time.localtime()
print(now)
time.struct_time(tm_year=2021, tm_mon=1, tm_mday=22, tm_hour=16, tm_min=14, tm_sec=30, tm_wday=4, tm_yday=22, tm_isdst=0)
import time
now=time.localtime()
print(now)
s=time.mktime(now)
print(s)
time.struct_time(tm_year=2021, tm_mon=1, tm_mday=22, tm_hour=16, tm_min=21, tm_sec=1, tm_wday=4, tm_yday=22, tm_isdst=0)
1611303661.0
import time
now=time.time()
print(now)
s=time.gmtime(now)
print(s)
1611303823.960081
time.struct_time(tm_year=2021, tm_mon=1, tm_mday=22, tm_hour=8, tm_min=23, tm_sec=43, tm_wday=4, tm_yday=22, tm_isdst=0)
import time
now=time.time()
print(now)
s=time.gmtime(now)
print(s)
new=time.asctime(s)
print(new)
1611303959.5288363
time.struct_time(tm_year=2021, tm_mon=1, tm_mday=22, tm_hour=8, tm_min=25, tm_sec=59, tm_wday=4, tm_yday=22, tm_isdst=0)
Fri Jan 22 08:25:59 2021
import time
now=time.time()
print(now)
s=time.ctime(now)
print(s)
1611304057.0304146
Fri Jan 22 16:27:37 2021
import time
print("start:",time.ctime())
time.sleep(9)
print("end:",time.ctime())
start: Fri Jan 22 16:29:58 2021
end: Fri Jan 22 16:30:07 2021
import datetime
print(datetime.MAXYEAR) #支持的最大年份
print(datetime.MINYEAR) #支持的最小年份
print(datetime.date.today()) #today返回当天日期
print(datetime.date.today().weekday()) #weekday放回当天的星期
print(datetime.date.today().isoformat()) #返回IOS格式
9999
1
2021-01-22
4
2021-01-22
import datetime
print(datetime.time()) #默认时间
print(datetime.time.max) #支持的最大时间
print(datetime.time.min) #支持的最小时间
00:00:00
23:59:59.999999
00:00:00
datetime=date+time,同时返回日期和时间
import datetime
today=datetime.datetime.today()
print(today)
print(datetime.datetime.now()) #与today用法相同
print(datetime.datetime.utcnow()) #0时区时间
now=datetime.datetime.now()
print(now.date()) #date对象返回日期
print(now.time()) #time对象返回时间
2021-01-22 18:22:42.380595
2021-01-22 18:22:42.382589
2021-01-22 10:22:42.382589
2021-01-22
18:22:42.382589
表示时间差
import datetime
dt1=datetime.datetime.now()
dt2=datetime.timedelta(weeks=2)+dt1
print(dt1)
print(dt2)
print(dt1-dt2)
2021-01-22 18:34:31.429461
2021-02-05 18:34:31.429461
-14 days, 0:00:00
import calendar
print(calendar.isleap(2000))
print(calendar.isleap(2018))
True
False
import calendar
print(calendar.leapdays(1900,2000))
24
四个参数:theyear,themonth,w(字符间距),l(行间距)
import calendar
print(calendar.month(2021,1))
import calendar
print(calendar.monthcalendar(2021,1))
[[0, 0, 0, 0, 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, 31]]
import calendar
print(calendar.monthrange(2021,1))
(4, 31)
import calendar
print(calendar.weekday(2021,1,1))
4
import calendar
print(calendar.calendar(2021))