我有两次NaN
和start_time
。
对于开始时间,我收到end_time
,而对于end_time,我收到6:30
。
现在我只想减去时间。我从html文本字段中得到这个。
如何减去这两个时间字段?
提前致谢
答案 0 :(得分:2)
>>> import datetime
>>> time1 = datetime.datetime.strptime("6:30",'%H:%M')
>>> time2 = datetime.datetime.strptime("7:30",'%H:%M')
>>> difference = time2-time1
>>> difference
datetime.timedelta(0, 3600)
>>> difference.seconds
3600
>>> "{:0>8}".format(datetime.timedelta(seconds=difference.seconds))
'01:00:00'
>>> "{:0>8}".format(datetime.timedelta(seconds=666777))
'7 days, 17:12:57'
答案 1 :(得分:0)
>>> from datetime import datetime
>>> s1 = "06:30"
>>> s2 = "07:30"
>>> timeformat = "%I:%M"
>>> delta = datetime.strptime(s2, timeformat) - datetime.strptime(s1, timeformat)
>>> delta
datetime.timedelta(0, 3600)
>>> delta.seconds
3600
delta
是时差。您可以检查值并相应地进行转换。