[英]Extract Date from a Datetime string
I need to get the dates from strings of type '08-JAN-20 12.00.00.000000000 AM'
in Python.我需要从 Python 中类型为'08-JAN-20 12.00.00.000000000 AM'
的字符串中获取日期。 How can I do this?我怎样才能做到这一点?
I tried this:我试过这个:
import datetime
datetime.strptime('08-JAN-20 12.00.00.000000000 AM', '%d-%b-%y %I.%M.%S %p')
but it says time data但它说的是时间数据
'08-JAN-20 12.00.00.000000000 AM' does not match format '%d-%b-%y %I.%M.%S %p'
Edit string first?先编辑字符串? For example例如
_string = '08-JAN-20 12.00.00.000000000 AM'
_string = _string.split()[0]
The variable now equals '08-JAN-20'.该变量现在等于“08-JAN-20”。 So %d-%b-%y should work.所以 %d-%b-%y 应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.