1 /** 2 * 获取系统当前时间 3 */ 4 function getNowYearMouth(){ 5 var date=new Date; 6 var nowYearMouth=date.getMonth()+1; 7 var year=date.getFullYear(); 8 var day = date.getDate(); 9 nowYearMouth =(nowYearMouth<10 ? "0"+nowYearMouth:nowYearMouth); //获取当前时间----月份 10 var nowYearMouthCur = (year.toString()+"-"+nowYearMouth.toString()); //获取当前时间----年月 11 var beforsixYearMouthday= getBeforeYearMouthDay(); 12 return nowYearMouthCur; 13 } 14 15 /** 16 * 获取系统当前年月日 17 */ 18 function getNowYearMouthDay(){ 19 var date=new Date; 20 var nowYearMouth=date.getMonth()+1; 21 var year=date.getFullYear(); 22 var day = date.getDate(); 23 nowYearMouth =(nowYearMouth<10 ? "0"+nowYearMouth:nowYearMouth); //获取当前时间----月份 24 day=(day<10?"0"+day:day); 25 var nowYearMouthDay = (year.toString()+"-"+nowYearMouth.toString()+"-"+day.toString());//获取系统当前的年月日 26 return nowYearMouthDay; 27 } 28 29 30 31 /** 32 * 获取系统前六个月时间--年月 33 */ 34 function getbeforeYearMouth() { 35 var date=new Date; 36 // date = new Date( date - 86400000 * 30 * 10 ); 37 var month=date.getMonth()+1; 38 var year=date.getFullYear(); 39 for (var i=0;i<6;i++) 40 { 41 if(month<=0) 42 { 43 month = month+12; 44 year--; 45 } 46 var tempmonth =(month<10 ? "0"+month:month); 47 var mydate = year.toString()+"-"+tempmonth.toString(); 48 month--; 49 } 50 return mydate; 51 } 52 /** 53 * 获取系统前六个月的年月日 54 */ 55 function getBeforeYearMouthDay(){ 56 var tempmonth; 57 var date=new Date; 58 var month=date.getMonth()+1; 59 var year=date.getFullYear(); 60 var day = date.getDate(); 61 for (var i=0;i<=12;i++){ 62 if(month<=0) { 63 month = month+12; 64 year--; 65 } 66 tempmonth =(month<10 ? "0"+month:month); 67 month--; 68 } 69 if((year%100!=0)&(year%400==0)&&(year%4==0)){//是闰年的情况下 70 if(tempmonth==2){ //若果是2月份 71 if(day>29){ 72 tempmonth = tempmonth+1; 73 }else{ 74 tempmonth = tempmonth; 75 } 76 }else{//不是2月份的情况 77 tempmonth = tempmonth; 78 } 79 }else{//不是闰年的情况下 80 if(tempmonth==2){ //若果是2月份 81 if(day>28){ 82 tempmonth = tempmonth+1; 83 }else{ 84 tempmonth = tempmonth; 85 } 86 }else{//不是2月份的情况 87 tempmonth = tempmonth; 88 } 89 } 90 if(day<10){ 91 day="0"+day; 92 } 93 var beforeYearMouthDay = year.toString()+"-"+tempmonth.toString()+"-"+day.toString(); 94 return beforeYearMouthDay; 95 }
时间: 2024-10-08 13:40:50