# 可以做一些计算之类的操作import datetime
# 获取现在或今天的日期和时间
t = datetime.datetime.now()print(datetime.datetime.today())print(datetime.datetime.now())# 通过获取的日期时间的对象,就可以通过对象的属性,获取对应的年,月,日,时,分,秒print(t.year)print(t.month)print(t.day)print(t.hour)print(t.minute)print(t.second)
===================================
# 可以算出n天后的日期
t = datetime.datetime.now()
result = t + datetime.timedelta(days=7)print(t, result)
获取两个日期之间的时间差
first = datetime.datetime(2021,12,1,12,32,44)
second = datetime.datetime(2021,12,2,12,42,44)print(first, second)
delta = second - first
print(delta)print(delta.total_seconds())