关于datetime的一些操作
import datetime
# 获取当前时间
now1 = datetime.datetime.now() # datetime.datetime(2020, 5, 31, 16, 1, 10, 477441)
# 获取今天
today = datetime.date.today() # datetime.date(2020, 5, 31)
# datetime <==>string
S = now1.strftime("%Y-%m-%d %H:%M:%S") # '2020-05-31 16:01:10'
datetime.datetime.strptime(S, "%Y-%m-%d %H:%M:%S") # datetime.datetime(2020, 5, 31, 16, 1, 10)
# timestamp <==> datetime
Tp = datetime.datetime.timestamp(now1) # 1590912070.477441
datetime.datetime.fromtimestamp(Tp) # # datetime.datetime(2020, 5, 31, 16, 1, 10, 47744)
# 日期加减
D = datetime.timedelta(days=1) # datetime.timedelta(days=1)
yesterday = today - D # datetime.date(2020, 5, 30)
tomorrow = today + D # datetime.date(2020, 6, 1)