js获取当前月份方法

1

	function date()
	{
		 var date=new Date;
		 var month=date.getMonth()+1;
		 month =(month<10 ? "0"+month:month); 
		 var mydate = (year.toString()+month.toString());
		 alert(month);var year=date.getFullYear(); 
	}

2

//获取完整的日期
 var date=new Date;
 var year=date.getFullYear(); 
 var month=date.getMonth()+1;
 month =(month<10 ? "0"+month:month); 
 var mydate = (year.toString()+month.toString());


3 获取前6个月的日期

function date()  
	{  
	     var date=new Date;  
	     date = new Date( date - 86400000 * 30 * 10 );
	     var month=date.getMonth()+1; 
	     var year=date.getFullYear();
	     for (var i=0;i<6;i++)
	     {
	    	 if(month<=0)
	    	 {
	    	 	month = month+12;
	    	 	year--;
	    	 }
	    	 var tempmonth =(month<10 ? "0"+month:month); 
		     var mydate = (year.toString()+tempmonth.toString());  
		     alert(mydate);
		     month--;
	     }
	     
	}   


你可能感兴趣的:(JavaScript)