判断年份的日期处理函数工具包/***判断年份*@param{string}yearyear*@return{Boolean}*/exportconstisLeap=function(year){if((year%4===0&&年%100!==0)||(年%400===0)){returntrue}returnfalse};getweek/***getweek*@param{string}datedate*@return{string}week*/exportconstgetWeek=function(date){letStamp=newDate(date)//返回周[Stamp.getDay()];letweeks=['day','one','two','three','four','five','six'];返回周[Stamp.getDay()];};获取月中的天数/***获取月中的天数*@param{string}yearyear*@param{string}monthmonth*@return{number}monthdays*/exportconstgetMonthDays=function(year,month){month=parseInt(month)-1if(month<0||month>11)return''letmonths=[31,28,31,30,31,30,31,31,30,31,30,31]if(this.isLeap(year)){months[1]=29}returnmonths[month]};number零填充用于格式化日期/***数字零填充*@param{string}str*@return{string}*/exportconstzero=function(str){str=parseInt(str)returnstr>9?海峡:'0'+海峡};获取今天的日期/***获取今天的日期*@param{string}str日期格式*@return{string}格式化日期*/exportconstgetToday=function(str){constdate=newDate();constyear=date.getFullYear(),month=zero(date.getMonth()+1),day=zero(date.getDate()),hour=zero(date.getHours()),minute=zero(date.getMinutes()),second=zero(date.getSeconds());让res='';switch(str){case"yyyy-mm-dd":res=年+'-'+月+'-'+日;休息;case"mm-dd-yyyy":res=month+'-'+day+'-'+year;休息;case"yyyy-mm-ddhh:MM:ss":res=year+'-'+month+'-'+day+''+hour+':'+minute+':'+second;休息;case"hh:MM:ss":res=hour+':'+minute+':'+second;休息;case"yyyy":res=year;休息;case"mm-dd":res=month+'-'+day;'参数错误';休息;}returnres;}获取前一天的日期/***获取前一天的日期*@param{string}str当前日期*@return{string}前一天的日期*/exportconstgetYesterday=function(str){letdate=str.split('-');让year=parseInt(date[0]),month=parseInt(date[1]),day=parseInt(date[2]);if(month>12||month<1||day>getMonthDays(year,month))return'dateisinvalid';天-=1;如果(日>0){返回年+'-'+零(月)+'-'+零(日);}月-=1;if(month>0){returnyear+'-'+zero(month)+'-'+getMonthDays(year,month);}年-=1;returnyear+'-'+12+'-'+getMonthDays(year,12);};获取第二天的日期/***获取第二天的日期*@param{string}str当前日期*@return{string}第二天的日期*/exportconstgetTomorrow=function(str){letdate=str.split('-');让year=parseInt(date[0]),month=parseInt(date[1]),day=parseInt(date[2]);if(month>12||month<1||day>getMonthDays(year,month))return'dateisinvalid';天+=1;如果(日<=getMonthDays(年,月)){返回n年+'-'+零(月)+'-'+零(日);}月+=1;如果(月<13){返回年+'-'+零(月)+'-'+'01';}年+=1;返回年份+'-'+'01'+'-'+'01';}todo获取当前周数并添加您可以在评论中告诉我的任何其他内容。
