gpt4 book ai didi

python - 将等格式转换为日期时间

转载 作者:太空宇宙 更新时间:2023-11-04 04:06:28 24 4
gpt4 key购买 nike

我在将同种格式转换为日期时间时遇到问题。我有这个:

[{'timex-value': '2019-W32T15:00', 'start': 18, 'end': 31, 'text': '3pm next week', 'type': 'TIME', 'value': '2019-W32T15:00'}]

如何在 python 中将“2019-W32T15:00”转换为日期时间格式?

最佳答案

要获取日期时间对象,您需要这样的东西。但是,您不会得到正确答案,因为您没有星期几。

import date time as dt
dt.datetime.strptime('2019-W32T15:00','%Y-W%WT%H:%M')

如果您希望成功转换为日期时间,则通过向 timex-value 字符串添加 1 来指定该周的第一天。

import date time as dt
dt.datetime.strptime('2019-W32T15:00'+'-1','%Y-W%WT%H:%M-%w')

结果:datetime.datetime(2019, 8, 12, 15, 0)

关于python - 将等格式转换为日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57263665/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com