从日期时间字符串中提取日期

问题描述 投票:0回答:1

我需要从Python中'08 -JAN-20 12.00.00.000000000 AM'类型的字符串中获取日期。我该怎么办?

我尝试过:导入日期时间datetime.strptime('08 -JAN-20 12.00.00.000000000 AM','%d-%b-%y%I.%M.%S%p')但它说时间数据'08 -JAN-20 12.00.00.000000000 AM'与格式'%d-%b-%y%I.%M.%S%p'不匹配]

python date datetime parsing format
1个回答
0
投票

首先编辑字符串?例如

_string = '08-JAN-20 12.00.00.000000000 AM'
_string = _string.split()[0]

该变量现在等于'08 -JAN-20'。因此%d-%b-%y应该可以工作。

© www.soinside.com 2019 - 2024. All rights reserved.