在 python 中将字符串转换为巴西日期格式时出错
我无法将巴西标准中的日期转换为 Python 中的日期。我尝试了下面的代码,但没有成功。
import datetime
datetime.datetime.strptime('5 de fevereiro de 2022', '%d-%b-%y').date()
ValueError: time data '5 de fevereiro de 2022' does not match format '%d-%b-%y'
我的目标是转换列表中这种格式的所有日期,如下所示:
['app', '5 de fevereiro de 2022', '6 de fevereiro de 2022', '7 de fevereiro de 2022', '8 de fevereiro de 2022']
I couldn't convert this date in the Brazilian standard to a date in Python. I tried the code below but it didn't work.
import datetime
datetime.datetime.strptime('5 de fevereiro de 2022', '%d-%b-%y').date()
ValueError: time data '5 de fevereiro de 2022' does not match format '%d-%b-%y'
My goal is to convert all dates in this format that are in a list, like this one below:
['app', '5 de fevereiro de 2022', '6 de fevereiro de 2022', '7 de fevereiro de 2022', '8 de fevereiro de 2022']
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试使用另一个库 dateparser
输出:
You can try with another library, dateparser
Output:
设置您的区域设置:
...最重要的是,使用正确的解析指令。
set your locale:
...and most importantly, use the correct parsing directive.