📌  相关文章
📜  python代码示例中的12小时制到24小时制

📅  最后修改于: 2022-03-11 14:45:34.170000             🧑  作者: Mango

代码示例3
def timeConversion(s):
    suffix = s[-2:]
    h_str = s[0:2]

    if suffix == 'PM':
        hh = int(h_str) % 12 + 12
    else:
        hh = int(h_str) % 12
    return s.replace(h_str, str(hh).zfill(2), 1)[:-2]


s = '12:00:00AM'
print(timeConversion(s))
# output: 00:00:00