当前位置:网站首页>解析各种文本的年月日
解析各种文本的年月日
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)
边栏推荐
猜你喜欢
随机推荐
MySQL 索引详解和什么时候创建索引什么时候不适用索引
飞机大战完整版
用C语言来实现扫雷小游戏
【DC-5靶场渗透】
HarmonyOS应用开发培训第二次作业
用scikit-learn学习谱聚类
跨域错误的原因及处理方法
MySQL 索引检索原理和B+Tree数据结构详解
ansible的安装和部署详细过程,配置清单基本操作
OptionError: ‘Pattern matched multiple keys‘
网络流媒体下载的 10 种方法(以下载 Echo 音乐为例)
网卡软中断过高问题优化总结
曲线特征----曲线弯曲程度的探究
junit总结
浅谈函数递归汉诺塔
-最高分-
C-PHY速率
下拉框数据字典应用案例
NotImplementedError: file structure not yet supported
【Nmap与Metasploit常用命令】









