将字符串转换为datetime.time对象


77

string以这种格式给出的"HH:MM",例如"03:55",代表3小时55分钟

我想将其转换为datetime.time对象以便于操作。最简单的方法是什么?

Answers:



14
>>> datetime.time(*map(int, '03:55'.split(':')))
datetime.time(3, 55)

虽然可以正常使用,但与使用解决方案相比,我发现阅读起来不太清楚datetime.strptime()
viam0Zah
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.