Pixelbox

Welcome to Pixelbox. Friday the 10 of October 2008

Skip to content >>

Caculating Dates in AS3

Here is a little example of how to return a date a set number of days from any given date in ActionScript 3 (Flex, AIR).

I used the example to return a set number of days since one of our issues launched, by sending the function the number of days and the starting date.


/* This is a public static function so it can be called from my 
utility class of useful converts and such! */

public static function returnDateXDaysFromY( x:Number , y:Date ):Date
{
  var xDaysFromY:Date = new Date(); // Date to return
  // I have removed a call to a function to set the time to zero, you can get caught out with summer time etc
  x = ((((x * 24)* 60) * 60) * 1000); // Turn days to miliseconds
  xDaysFromY.setTime( x + y.getTime() ); 
  return xDaysFromY;
}



Hopefully someone else out there will find this handy :)

Meta tags: AIR, ActionScript, Flex

There are no comments yet

Add your own comment