Parse datetime with hours 1-24 instead of 0-23

后端 未结 3 1852
無奈伤痛
無奈伤痛 2020-12-21 06:28

I have a data source that contains datetime\'s I\'m reading in Python. The program always dies on the 24th hour, since python holds dates 0-23 not 1-24.

Considering

3条回答
  •  爱一瞬间的悲伤
    2020-12-21 07:11

    I'd probably just go for something simple like:

    from datetime import datetime
    import re
    
    s = '2012/15/01 24'
    y, d, m, h = map(int, re.findall('\d+', s))
    dt = datetime(y, m, d, h - 1)
    # 2012-01-15 23:00:00
    

提交回复
热议问题