>>> from dateutil.parser import parse
>>> from datetime import datetime
>>> """
... 求两个时间差
... time2 - time1
... """
'\n求两个时间差\ntime2 - time1\n'
>>> def get_timedifference(time1,time2):
... a=parse(time1)
... b=parse(time2)
... timedifference=(b-a).seconds
... print("时间差为:"+str(timedifference))
... return timedifference
...
>>> time1=["2018-03-20T12:10:57","2018-03-20T12:11:36","2018-03-20T12:15:42"]
>>> time2=["2018-03-20T12:12:11","2018-03-20T12:13:08","2018-03-20T12:18:09"]
>>> time=list(map(lambda x:get_timedifference(x[0],x[1]),zip(time1,time2)))
时间差为:74
时间差为:92
时间差为:147
>>>time
[74, 92, 147]
Python3时间list中,两个list对应相减
最新推荐文章于 2024-05-31 09:59:05 发布