【问题标题】:Converting time in %H:%M:%S:%f of 83 days, 17:02:10.401369 python在 83 天的 %H:%M:%S:%f 中转换时间,17:02:10.401369 python
【发布时间】:2021-07-25 12:29:22
【问题描述】:

我需要将'83 days, 17:02:10.401369'的时间格式转换为%H:%M:%S:%f

res_time = '83 days, 17:02:10.401369'
                
res_formated = datetime.strptime(res_time, "%H:%M:%S.%f")

值错误:时间数据“83 天,17:02:10.401369”与格式“%H:%M:%S.%f”不匹配

【问题讨论】:

标签: python django datetime timedelta


【解决方案1】:

就像@Klaus D. 说的,使用 split 来使用字符串:

res_time = '83 days, 17:02:10.401369'

res_time = res_time.split(",")[1]

res_time = res_time.strip() // Delete the white space before and after the string

res_formated = datetime.strptime(res_time, "%H:%M:%S.%f")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-09
    • 2020-02-14
    • 1970-01-01
    • 2012-11-29
    • 2018-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多