[英]Converting 12 hr to 24 hr python shows 24:00:00 as 24:00:00 and not 00:00:00
當我使用以下代碼時。 我確實知道我要給定的時間加上12,並且它返回24:00:00,但我不明白如何獲取00:00:00。
我的時間戳記有時間值列表。
r = timestamp[:-2] if timestamp[-2:] == "AM" else str(int(timestamp[:2]) + 12) + timestamp[2:8]
使用模算術除以24並得到余數。 更改此:
int(timestamp[:2]) + 12
對此:
(int(timestamp[:2]) + 12) % 24
示范:
>>> 12 + 12
24
>>> (12 + 12) % 24
0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.