Jun 242010
 

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 !

  One Response to “Date arithmatic in Flex/Actionscripts”

  1. [...] Date arithmatic in Flex/Actionscripts » 李漾 Yang Li 's Blog [...]