python dateutil.parser 将字符串转换为字符,并且实现两个时间相减(Python dateutil.parser converts strings into characters and subtracts two times)

下载第三方模块

pip install python-dateutil

def  time_diff(t1,t2):
    t1 = parse(t1)
    t2 = parse(t2)
    ts = (t2-t1).total_seconds()
    int_ts = int(ts/60)
    return int_ts

print(time_diff('2021-11-23 22:43:55','2021-11-23 22:44:55'))

seconds:除去天数、小时后剩余的秒数

total_seconds: 总秒数,包含天、小时转换后的秒数

days:仅包含天,时分秒会被抛弃

————————

Download third party modules

pip install python-dateutil

def  time_diff(t1,t2):
    t1 = parse(t1)
    t2 = parse(t2)
    ts = (t2-t1).total_seconds()
    int_ts = int(ts/60)
    return int_ts

print(time_diff('2021-11-23 22:43:55','2021-11-23 22:44:55'))

Seconds: the number of seconds remaining after days and hours are removed

total_ Seconds: the total number of seconds, including the number of seconds after day and hour conversion

Days: only days, hours, minutes and seconds will be discarded