//------[获取两个日期中所有的月份中]
  function getMonthBetween(start,end){  
	var result = [];  
	var s = start.split("-");  
	var e = end.split("-");  
	var min = new Date();  
	var max = new Date();  
	min.setFullYear(s[0],s[1]);  
	max.setFullYear(e[0],e[1]);  
	  console.log(e[0]+"---- "+e[1]);
	var curr = min;  
	while(curr <= max){  
	    var month = curr.getMonth();  
	    //month=month==0?12:month;
	    console.log(month);
	    var str=curr.getFullYear()+"-"+(month);
	    var s=curr.getFullYear()+"-0";
	    if(str==s){
	    	str=curr.getFullYear()+"-12";
	    }
	    result.push(str);  
	    curr.setMonth(month+1);
	}  
	return result;  
 } 
//------[获取两个日期中所有的月份中END]


html

 <script>
   console.log(getMonthBetween('2017-7', '2018-2')); 
 </script>

效果图

JS[获取两个日期中所有的月份]

相关文章:

  • 2021-10-19
  • 2021-11-30
  • 2021-12-25
  • 2021-08-14
  • 2021-10-19
  • 2018-01-24
  • 2021-12-29
  • 2021-11-29
猜你喜欢
  • 2021-11-29
  • 2021-11-14
  • 2021-11-29
  • 2021-11-19
  • 2022-01-02
  • 2021-08-07
  • 2021-12-23
  • 2021-10-19
相关资源
相似解决方案