In ActionScript, how do you get the day number at the end of the month?
June Example
getEndOfMonth() returns 30;
July Example
getEndOfMonth() returns 31;
In ActionScript, how do you get the day number at the end of the month?
June Example
getEndOfMonth() returns 30;
July Example
getEndOfMonth() returns 31;
In many languages, you can achieve this by getting a date value for the zeroth day of the following month, then working it out from that. So maybe try:
var d:Date = new Date(2009,7,0);
var day:Number=d.getDate();
If that doesn't work, you can get the first day of the following month, and subtract a day
var millisecondsPerDay:int = 1000 * 60 * 60 * 24;
var d:Date = new Date(2009,7,1);
d.setTime(d.getTime() - millisecondsPerDay);
var day:Number=d.getDate();
There are only twelve of them (and one special case for leap years)--it wouldn't be that bad to just write it out.
static public function getEndOfMonth(month:uint, isLeap:Boolean = false):uint
{
return [31, 28 + isLeap, 31, 30, 30, 31, 31, 30, 31, 30, 31][month];
}
You can add an object called Month with const uints, for example Month.JANUARY == 0
and so on, encapsulate it etc etc...