datetime的在项目中的使用:
datetime是一个关于时间的库,主要含有:
-
date 日期对象,常用的属性有 year,month,day
-
time 时间对象, hour,minute,second,毫秒
-
datetime 日期时间对象,常用属性有hour,minute,second,microsecond
-
timedelta 时间间隔,两个时间点之间的长度
date:
import datetime
date = datetime.date(2020,3,24)
print(date)
print(type(date))
-----------------
2020-03-24
<class 'datetime.date'>
time:
import datetime
time_1 = datetime.time()
time_2 = datetime.time(7,33,44)
time_3 = datetime.time(7,33,44,1020)
print(time_1)
print(time_2)
print(time_3)
print(type(time_1))
-------------------------------------
00:00:00
07:33:44
07:33:44.001020
<class 'datetime.time'>
Datetime:
import datetime
datetime = datetime.datetime(2020,2,2,18,33,44)
print(datetime)
------------------------------------------------
2020-02-02 18:33:44
<class 'datetime.datetime'>
timedelta:
import datetime
from datetime import timedelta
dlt = timedelta(seconds=30)
print(dlt)
print(type(dlt))
-------------------------------------------
0:00:30
<class 'datetime.timedelta'>