time 模块
In [1]: import time
In [2]: time.time()
Out[2]: 1616426875.346216
In [3]: time.localtime()
Out[3]: time.struct_time(tm_year=2021, tm_mon=3, tm_mday=22, tm_hour=23, tm_min=28, tm_sec=1, tm_wday=0, tm_yday=81, tm_isdst=0)
In [4]: time.strftime("%Y-%m-%d %X", time.localtime())
Out[4]: '2021-03-22 23:28:59'
In [6]: time.strptime('2021-03-22 23:28:59', "%Y-%m-%d %X")
Out[6]: time.struct_time(tm_year=2021, tm_mon=3, tm_mday=22, tm_hour=23, tm_min=28, tm_sec=59, tm_wday=0, tm_yday=81, tm_isdst=-1)
datetime 模块
In [7]: import datetime
In [8]: datetime.datetime.today()
Out[8]: datetime.datetime(2021, 3, 22, 23, 33, 48, 31184)
In [9]: datetime.datetime.now()
Out[9]: datetime.datetime(2021, 3, 22, 23, 36, 31, 776767)
In [10]: datetime.datetime.today() - datetime.timedelta(days=1)
Out[10]: datetime.datetime(2021, 3, 21, 23, 37, 15, 337094)
In [11]: datetime.datetime.today() + datetime.timedelta(days=1)
Out[11]: datetime.datetime(2021, 3, 23, 23, 37, 38, 498012)