在datechooser组件中,我想获取一个月中特定列的所有日期值,例如:星期六在数组中出现的所有日期值。 任何人都可以帮助我如何在数组中获取这些列值。
由于
答案 0 :(得分:1)
我知道你是从DateChooser那里说的,但是如果没有其他人提出带有dateChooser的解决方案,作为后退你可以通过做类似的事情得到你想要的AS Date
对象:
function getSaturdaysFor(year:Number, month:Number, dayOfWeek:Number):Array {
var d:Date = new Date(year,month,1);
var toReturn:Array = new Array();
//Find the first occurance of the dayOfWeek
for(var i:int = 0; i < 7; i++){
if(d.day == dayOfWeek){
break;
} else {
d.date++;
}
}
//Find the remaning dayOfWeeks, skipping non-dayOfWeek dates
for(var n:int = 0; n < 7; n++){ //Up to 6 possible
if(d.month == month){
trace("Added " + d.date);
toReturn.push(d.date);
d.date += 7;
} else {
break; //No more target days of week
}
}
return toReturn;
}
//Call this function like
getSaturdaysFor(2012, 2, 6); //2012 March Saturdays
getSaturdaysFor(2012, 3, 0); //2012 April Sundays
答案 1 :(得分:1)
坦率地说,编写一个不使用DateChooser
function getDatesForDaysInMonth(year:Number, month:Number, dayOfWeek:Number):Array {
var dts:Array=[];
var dt:Date=new Date(year, month, 1);
var firstInSeries:Date=new Date(dt);
firstInSeries.date += (dayOfWeek-dt.day);
if(firstInSeries.month != month) {
firstInSeries.date += 7;
}
dts.push(firstInSeries);
for(var i:int=1; true; i++) {
var it:Date=new Date(firstInSeries.valueOf() + i*7*24*60*60*1000);
if(it.month != month) {
break;
}
dts.push(it);
}
return dts;
}
//tester function
function disp(a:Array):void {
for(var i:int=0; i<a.length; i++) {
trace(i + ": " + a[i].toString());
}
trace("------------------");
}
trace("Sat");
disp(getDatesForDaysInMonth(2012, 2, 6));
trace("Fri");
disp(getDatesForDaysInMonth(2012, 2, 5));
trace("Thu");
disp(getDatesForDaysInMonth(2012, 2, 4));
trace("Wed");
disp(getDatesForDaysInMonth(2012, 2, 3));
trace("Tue");
disp(getDatesForDaysInMonth(2012, 2, 2));
trace("Mon");
disp(getDatesForDaysInMonth(2012, 2, 1));
trace("Sun");
disp(getDatesForDaysInMonth(2012, 2, 0));