Python之datetime库
字符串时间转datetime时间
from datetime import datetime
b='2021-04-26 11:23:56'
c = datetime.strptime(b, "%Y-%m-%d %H:%M:%S")
print(c) # datetime.datetime(2021, 4, 26, 11, 23, 56)
计算两个datetime时间差(单位秒)
from datetime import datetime
a = datetime.now()
c = datetime.datetime(2021, 4, 26, 11, 23, 56)
d = (a-c).seconds
print(d) # 2401 (秒)