python strptime format with optional bits

后端 未结 7 668
慢半拍i
慢半拍i 2020-12-03 09:51

Right now I have:

timestamp = datetime.strptime(date_string, \'%Y-%m-%d %H:%M:%S.%f\')

This works great unless I\'m converting a string tha

7条回答
  •  离开以前
    2020-12-03 10:05

    I'm late to the party but I found if you don't care about the optional bits this will lop off the .%f for you.

    datestring.split('.')[0]

提交回复
热议问题