【发布时间】:2018-09-15 11:20:03
【问题描述】:
我已经查看了与 strptime 和未转换的数据剩余相关的其他问题,但很难找出我在代码中哪里出错了。
currentTime = format(currentTime, '%H:%M:%S')
#remove the current time from phone time
timeDifferenceValue = datetime.datetime.strptime(str(currentTime), FMS) - datetime.datetime.strptime(
str(ptime) + ":00", FMS)
else:
time_left = time_left[-7:]
time_leftHatch = datetime.datetime.strptime(time_left, FMS) - timeDifferenceValue
time_leftHatch = format(time_leftHatch, '%H:%M:%S')
在这个阶段发现了错误:
time_leftHatch = datetime.datetime.strptime(time_left, FMS) - timeDifferenceValue
timeleft 和 timeDifference 的值分别是:
time_left = 1:29:47 timeDifferenceValue = 0:13:31
错误: 未转换的数据仍然存在::47
约翰在 cmets 中提到我应该更改删除不必要的 strptime 的过度使用。这似乎已经解决了未转换的数据剩余。
例如,timeDifferenceValue 已经是时间格式,所以根本不需要更改。
有什么想法吗?
【问题讨论】:
-
您可以将代码简化为一个失败的
strptime。请这样做,并发布输入字符串和格式字符串,不要有多余的其他代码。 -
嗨,约翰,感谢您的评论。抱歉,我对 Python 还很陌生,但我不太清楚你把它变成一个单一的 strptime 是什么意思。代码中几乎所有的值实际上都是字符串(不包括我认为的字符串——我现在已经从中删除了 strptime)。通过删除这个 strptime,它似乎已经解决了这个问题。我不明白多么不幸,因为我认为它会由于 FMS 而转换。我现在会删除所有不必要的代码。再次感谢!
标签: python-3.x strptime