我有情况我应该忽略日期字符串中的时间戳.我尝试过以下命令,但没有运气.
"start" variable used below is in AbsTime (Ex: 01MAY2017 11:45) and not a string.
start_date = datetime.datetime.strptime(start, '%d%^b%Y').date()
print start_date
Run Code Online (Sandbox Code Playgroud)
我的输出应该是:
01MAY2017或01MAY2017 00:00
任何人都可以帮助我.
您的指令略有偏差,您需要捕获所有内容(无论您想要保留什么).
start_date = datetime.datetime.strptime(start, '%d%b%Y %H:%M').date()
print start_date.strftime('%d%b%Y')
# '01May2017'
Run Code Online (Sandbox Code Playgroud)
更新 - 在下面添加完整代码:
import datetime
start = '01MAY2017 11:45'
start_date = datetime.datetime.strptime(start, '%d%b%Y %H:%M').date()
print start_date.strftime('%d%b%Y')
# 01May2017
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8691 次 |
| 最近记录: |