资源描述:
《shell日期处理函数》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、shell日期处理函数#######################################SHELLdatefunction##1:(check_leap)todeterminewhetheraleapyear##2:getsthemaximumdategetmondays(#)JuneThedateof#3:(check_date)#checkformat#4:(getbeforedate)#datebacktoyesterday#5:(getnextdate)#dateofreturntomorrow#6:returnsthemonthenddateYYYYMMDDget_c
2、ur_date()#7:returnsYYYYMMgetcurmonth()inthemonthofthemonth#8:returnslastmonth,sdateYYYYMMDD,getlastdate()#9:returnsYYYYMMget_last_month()lastmonth#######################################Todeterminewhetheraleapyear##input:year44-丄〃丄〃〃X?〃〃#output:true,faseCheck_leap(){Y二'exptsubstr$114'Rl='expr$Y%4R2
3、二'expt$Y%100'R3二'expt$Y%400'If[$rl,-eq,0,-a,$r2,-ne,0,-o,$r3,-eq,0]ThenFRUN二〃tme〃〃ElseFRUN二"false"FiEcho$FRUN#getsthemaximumdatemonthMethods1#Get_mon_days(){Y='exprsubstr$114M二'exptsubstr$152'Case〃$『in01
4、03
5、05
6、07
7、08
8、10
9、12)days二31;;04
10、06
11、09
12、ll)days二30;;02)_tmpStr='checkleap〃$Y"#'todeterminewhethera
13、leapyearIf[[$_tmpStr'二'truethen#leapyearDays二29ElseDays=28Fi••VV*)Days二0••ESAC环氧氯丙烷o$b}Dearsirsre#getsthemaximumdatemonthMethods2#Get_mon_days2()Y二exprsubstr$114exprsubstr$152'#fromtheendofthemonthwhenthelastdayAa='cal$M$Y'#calendarDays二'echo$aaawk'{print$NF}Echo$daysCheckthedate#format(forexample
14、:20090227)#returnstatus($0?)1illegallegitimateCheckdate(){#checkincomingoneparameter]1]&&echol&&exit1-ne$#Check#stringlength_lenSti-'exprlength〃$1"?[$_lenStr,-ne8]&&echol&&exit1#checkwhethertheinputisnotthebeginningofthe0digital_tmpStr='echo〃$1〃grep[0-9]*$〃,[-z,〃$_tinpStT〃]&&echol&&exit1Y二exprsubs
15、tr$114M二exprsubstr$152'D二exprsubstr$172'#checkin-It1,-o,$M,-gt12]&&echol&&exit1#takethenumberofdaysofthemonthDays='get_mon_days〃$Y$M〃Checkon#]〃$D〃,-It1,-o,$D,-gt,$days,&&echol&&exit1Echo0}##returndateyesterdayGet_before_date(){Y='exprsubstr$114exprsubstr$152'D二exprsubstr$172'A#01OctobercaseIf[[$D]
16、-eq01ThenIf[[$M]-eq01ThenA01year#Sept.01caseFromtheendoflastyear#date(December31st)YY二expr$Y-1Be_date=〃${YY}1231〃〃Else#fromtheendofMM二expt$M-1MM二'printf〃%02d〃Dad二'getmondayslastmonthdate〃$Y$MM〃Be_date=〃$Y$MM$dad〃