当前位置:网站首页>解析各种文本的年月日
解析各种文本的年月日
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)
边栏推荐
猜你喜欢
随机推荐
Sqli-labs-master靶场1-23关通关详细教程(基础篇)
处理异步事件的三种方式
第三次HarmonyOS培训
对角矩阵(diagonal matrix)
junit总结
【三子棋】7.25
-飞机大战-
关于semantic-ui的cdn失效问题(怎样通过本地引用semantic-ui)
ss-3.工程重构
MySQL 索引详解和什么时候创建索引什么时候不适用索引
web安全-PHP反序列化漏洞
如何不耍流氓的做运维之-SHELL脚本
编写一个函数 reverse_string(char * string)(两种方法实现)7.26
【函数与递归】7.19
-最高分-
breed Web刷机升级详细教材修正编译器固件说明_itkeji.top
dataframe插入一列
D-PHY
【反弹shell与提权】
7.7(5)