我正在尝试将12小时制的时间转换为24小时制的时间...
自动示例时间:
06:35 ## Morning
11:35 ## Morning (If m2 is anywhere between 10:00 and 12:00 (morning to mid-day) during the times of 10:00 and 13:00 (1pm) then the m2 time is a morning time)
1:35 ## Afternoon
11:35 ## Afternoon
示例代码:
m2 = "1:35" ## This is in the afternoon.
m2 = datetime.strptime(m2, "%H:%M")
print m2
预期输出:
13:35
实际输出:
1900-01-01 01:35:00
我尝试了第二个变化,但仍然没有帮助 :/
m2 = "1:35" ## This is in the afternoon.
m2split = m2.split(":")
if len(m2split[0]) == 1:
m2 = ("""%s%s%s%s""" % ("0", m2split[0], ":", m2split[1]))
print m2
m2temp = datetime.strptime(m2, "%I:%M")
m2 = m2temp.strftime("%H:%M")
我做错了什么,该怎么修正?
strptime()
会假定它是上午时间。要表示下午时间,需要使用一些形式的上午/下午指示器。 - Jonathan Leffler