>>> import datetime
>>>
datetime.datetime.now()
datetime.datetime(2019, 3, 3, 15, 7, 30, 931160)
>>> now = datetime.datetime.now()
>>> now
datetime.datetime(2019, 3, 3, 15, 8, 5, 66884)
>>> yesterday = datetime.datetime(2019,3,2,15,0,0,0)
>>> yesterday
datetime.datetime(2019, 3, 2, 15, 0)
>>> now-yesterday
datetime.timedelta(1, 485, 66884)
>>>
delta = now-yesterday
>>> delta
datetime.timedelta(1, 485, 66884)
>>> datetime.timedelta(1, 485, 66884)
datetime.timedelta(1, 485, 66884)
>>>
delta.days
1
>>>
delta.total_seconds()
86885.066884
>>>
after = now+datetime.timedelta(days=2)
>>> after
datetime.datetime(2019, 3, 5, 15, 8, 5, 66884)
>>> yesterday
datetime.datetime(2019, 3, 2, 15, 0)
>>> now
datetime.datetime(2019, 3, 3, 15, 8, 5, 66884)
>>>
after = now+datetime.timedelta(seconds=10002)
>>> after
datetime.datetime(2019, 3, 3, 17, 54, 47, 66884)
>>> import time
>>> lst = []
>>> for i in
range(5):
... lst.append(datetime.datetime.now())
...
time.sleep(1)
...
>>> lst
[datetime.datetime(2019, 3, 3, 15, 24, 41, 101860), datetime.datetime(2019, 3, 3, 15, 24, 42, 102824), datetime.datetime(2019, 3, 3, 15, 24, 43, 103479), datetime.datetime(2019, 3, 3, 15, 24, 44, 104411), datetime.datetime(2019, 3, 3, 15, 24, 45, 104583)]
>>> for i in lst:
... print(i)
...
2019-03-03 15:24:41.101860
2019-03-03 15:24:42.102824
2019-03-03 15:24:43.103479
2019-03-03 15:24:44.104411
2019-03-03 15:24:45.104583
>>>