Thursday, December 11, 2008

Parsing a Date String in Actionscript 3

I had a little trouble with this today. I tried to find how I could create a Date Object by parsing a string. I wanted the string to be created as a UTC time and I wanted to be able to read it back as milliseconds. I wasted a lot of time and I guess by what I've been reading on the web that a lot of people have had similar issues. It turns out to be very simple. Tragic I spent several hours on it.

here it is:

var milliseconds:Number = Date.parse("12/11/2008 15:00:00 UTC");

acheive the same result with:

var milliseconds:Number = Date.UTC(2008, 11, 11, 15);

To get your string back

var DateObj = new Date(milliseconds);
var UTCDateString = DateObject.toUTCString();

That's all I need, hope this helps someone.