当前位置:网站首页>解析各种文本的年月日
解析各种文本的年月日
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)
边栏推荐
猜你喜欢
随机推荐
7.8(6)
7.21[日常]
ss-2.子项目互相访问(order80 -> payment8001)
【函数与递归】7.19
pta a.1003 的收获
第四次培训
快速上手 Mockito 单元测试框架
轨迹(形状)相似性判断与度量方法
2017-06-11 Padavan 完美适配newifi mini【adbyby+SS+KP ...】youku L1 /小米mini
Go (一) 基础部分3 -- 数组,切片(append,copy),map,指针
用pulp库解决运输问题【详细】
求因子数量
【XSS,文件上传,文件包含】
flask 面试题 问题
用scikit-learn学习谱聚类
Navicat 解决隔一段时间不操作出现延时卡顿问题
Flask的简单介绍及使用方法简介
【CSRF,SSRF,XXE,PHP反序列化,Burpsuite】
初步认识ZK
uni-app 滚动到顶部/指定位置









