Date arithmatic in Flex/Actionscripts

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

Today I spent some time working on the date arithmetic. I don’t believe there is built-in Date arithmetic in Flex. Therefore, there probably only two solutions.

One is using DateUtils open source library: http://flexdateutils.riaforge.org/

The other one is converting date into milliseconds and then do deductions or additions.

public static const millisecondsPerMinute:int = 1000 * 60;
public static const millisecondsPerHour:int = 1000 * 60 * 60;
public static const millisecondsPerDay:int = 1000 * 60 * 60 * 24;
public static const millisecondsPerWeek:int = 1000 * 60 * 60 * 24*7;

var startDate:Date;
startDate = new Date(dateNow.getTime() – (millisecondsPerHour));
Note here, if we set millisecondsPerWeek to 1000 * 60 * 60 * 24*30, if will exceed the maximum value of a int number!(2^31)-1, which is 2,147,483,647 !

Read More