当前位置:网站首页>解析各种文本的年月日
解析各种文本的年月日
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)
边栏推荐
猜你喜欢
随机推荐
Djiango第四次培训笔记
浏览器多线程离屏渲染压缩打包方案
web安全-sql注入漏洞
Js学习笔记(四)
junit总结
7.21[日常]
-查找数-
OptionError: ‘Pattern matched multiple keys‘
Kaggle(四)Scikit-learn
【DC-4靶场渗透】
【转】最小描述长度准则MDL(Minimun Description Length)
7.16(6)
request.getParameter的结果为on
minio下载文件乱码或者是一条横线
breed Web刷机升级详细教材修正编译器固件说明_itkeji.top
Go (二) 函数部分1 -- 函数定义,传参,返回值,作用域,函数类型,defer语句,匿名函数和闭包,panic
用C语言来实现扫雷小游戏
斐讯K2路由编译Padavan华硕固件和心得
1.ROS环境搭建与基础工作
icebreaker的垃圾话学习指南









