当前位置:网站首页>解析各种文本的年月日
解析各种文本的年月日
2022-08-03 05:16:00 【stay_foolish12】
解析各种文本的年月日
def str2date(str_date):
str_date=str_date.strip()
if(len(str_date)>11):
str_date=str_date[:11]
if(str_date.find('-')>0):
year=str_date[:4]
if(year.isdigit()):
year=int(year)
else:
year=0
month=str_date[5:str_date.rfind('-')]
if(month.isdigit()):
month=int(month)
else:
month=0
if(str_date.find(' ')==-1):
day=str_date[str_date.rfind('-')+1:]
else:
day=str_date[str_date.rfind('-')+1:str_date.find(' ')]
if(day.isdigit()):
day=int(day)
else:
day=0
elif(str_date.find('年')>0):
year=str_date[:4]
if(year.isdigit()):
year=int(year)
else:
year=0
month=str_date[5:str_date.rfind('月')]
if(month.isdigit()):
month=int(month)
else:
month=0
day=str_date[str_date.rfind('月')+1:str_date.rfind('日')]
if(day.isdigit()):
day=int(day)
else:
day=0
elif(str_date.find('/')>0):
year=str_date[:4]
if(year.isdigit()):
year=int(year)
else:
year=0
month=str_date[5:str_date.rfind('/')]
if(month.isdigit()):
month=int(month)
else:
month=0
if(str_date.find(' ')==-1):
day=str_date[str_date.rfind('/')+1:]
else:
day=str_date[str_date.rfind('/')+1:str_date.find(' ')]
if(day.isdigit()):
day=int(day)
else:
day=0
if month<10:
month='0'+str(month)
if day<10:
day='0'+str(day)
return '%s-%s-%s' % (year,month,day)
边栏推荐
猜你喜欢
随机推荐
玩转Markdown(2) —— 抽象语法树的提取与操纵
-最低分-
request.getParameter的结果为on
第四次培训
【特征选取】计算数据点曲率
阿凡提的难题
Django从入门到放弃三 -- cookie,session,cbv加装饰器,ajax,django中间件,redis缓存等
【DC-2靶场渗透】
TypeError: Cannot read property ‘xxxx‘ of undefined的解决方法
Flask,1-2
NotImplementedError: file structure not yet supported
Modelarts第一次培训
深度学习入门之GRU
vim命令
2017-06-11 Padavan 完美适配newifi mini【adbyby+SS+KP ...】youku L1 /小米mini
Haproxy服务监控
自定义封装组件-国际化-下拉搜索
Flask,3-6
ss-3.工程重构
VSO Downloader Ultimate 5.0.1.45 中文多语免费版 在线视频下载工具








