I’ve updated my BatBeltTime utility class to include a method for returning the number of days in the month – something that should really be part of the Date class if you ask me.
BatBeltTime is a utility class that I put all my time/date conversion methods in. It has pretty much everything you might need for working with time for say a video player or converting between Actionscript <–>MySQL.
/**
* How many days are in this month? Returns: 28-31.
*/
public static function daysInThisMonth( month:int, fullYear:int ):int {
switch( month ) {
case 0: { // January
return 31;
}
case 1: { // February
if( fullYear % 4 == 0 ) {
return 29;
} else {
return 28;
}
}
case 2: { // March
return 31;
}
case 3: { // April
return 30;
}
case 4: { // May
return 31;
}
case 5: { // June
return 30;
}
case 6: { // July
return 31;
}
case 7: { // August
return 31;
}
case 8: { // September
return 30;
}
case 9: { // October
return 31;
}
case 10: { // November
return 30;
}
case 11: { // December
return 31;
}
default: {
return -1;
}
}
BatBeltTime also tells you things like:
- Convert numeric time to English. For example: 71 –> 1 hour and 21 minutes
- Get the name of the day from the date.
- Get the month name from the date.
- Get MySQL string from date
- Make a Date object from a MySQL date string
- Convert an MySQL Timestamp to an Actionscript Date. Thanks to Pascal Brewing for the beautiful simplicity.
- Convert an Actionscript Date to MySQL Timestamp. Thanks to Pascal Brewing for the beautiful simplicity.
- Convert an Actionscript Date to a MySQL Date
- Input the seconds and return a string of the form: hours:mins:secs
- Input the seconds and return a string of the form: mins:sec
- Input seconds and return a string of the form: hours:min
Why BatBeltTime?
In case you’re wondering I named it BatBeltTime because it’s a utility class that I hang useful methods on – like Batman hangs his cool utility tools on his belt.





You missed a special case with leap years. Not that they happen all that often, but the pedant in me had to say something. From Wikipedia: “Years that are evenly divisible by 100 are not leap years, unless they are also evenly divisible by 400, in which case they are leap years.”
@Josh No, I didn’t miss it. I left it out on purpose so that I could see who was the most pedantic reader here. Got’cha! :-)
I did read that before although I thought it was years % 1000 == 0 are leap years and not 400.
I still have a digital watch – that I never wear – that missed leap day in 2000. That was my Y2K failure.
oooooohh….I was needing this class for a project about a moth ago, it could have been very handy. I like the name, easy to remember when you’re in someone else’s computer.
Thank you Polygeek.