sameold
sameold

Reputation: 19242

Strange behavior when converting date

I'm working with a date string that looks like this

Wed Nov 30 22:51:20 +0000 2011

I'm trying to convert it to type Date in Actionscript. When I do this, I get the date in 1969.

asDate = new Date(asString); //or new Date(asString as String);

But if I create a class with static function that just does exactly the same thing, I get the real date in 2011.

asDate = MyDate.retDate(asString);

public class MyDate {
  public static function retDate(asString:String):Date {
     return new Date(asString);
  }
}

The class way works, but the simple way doesn't, even though what I'm doing in the class is exactly the same line as when I try to do it without the class. I thought maybe it has to do with the type, so I tried new Date(asString as String); but this also give the 1969 date.

Upvotes: 0

Views: 50

Answers (1)

laurent
laurent

Reputation: 90776

Did you try parsing the date using the static function Date::parse()? For example:

var date:Date = Date.parse(asString);

Upvotes: 1

Related Questions