直接上代码:
/* * This file is provided for custom JavaScript logic that your HTML files might need. * Maqetta includes this JavaScript file by default within HTML pages authored in Maqetta. */ require([ "dojo/ready","dojo/date" ],function(ready,dojoDate){ ready(function(){ //构建数组,用来存储时间段内的日期信息 var arrayObj = new Array(); //构建时间段的开始日期 var start_temp_date = "20121210"; var start_temp_year = start_temp_date.substring(0,4); var start_temp_month = start_temp_date.substring(4,6); var start_temp_day = start_temp_date.substring(6,8); var _start_temp_date = start_temp_year+"/"+start_temp_month+"/"+start_temp_day; var start_v_date = new Date(_start_temp_date); //构建时间段的结束日期 var end_temp_date = "20121215"; var end_temp_year = end_temp_date.substring(0,4); var end_temp_month = end_temp_date.substring(4,6); var end_temp_day = end_temp_date.substring(6,8); var _end_temp_date = end_temp_year+"/"+end_temp_month+"/"+end_temp_day; var end_v_date = new Date(_end_temp_date); //计算出开始日期到结束日期间的天数 var day_num = dojoDate.difference(start_v_date,end_v_date,'day'); alert(day_num); var v_date; //需要存储的日期信息 for(var i=0;i<=day_num;i++) { if(i==0) { v_date = start_v_date; }else { v_date = dojoDate.add(v_date,'day',1); } if(arrayObj.length==0) { arrayObj.push(v_date); }else { var v_flag = true; for(var k=0;k<arrayObj.length;k++) { if(dojoDate.compare(v_date,arrayObj[k])==0) { v_flag = false; break; } } if(v_flag) { arrayObj.push(v_date); } } } for(var j=0;j<arrayObj.length;j++) { alert(arrayObj[j]); } }); });