Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I parse a date in Flash AS3

I want to be able to parse my date based on the dd-MM-yyyy in flash however I can't quite get it.

Here is my code:

    var arrivalDate = String(arrivalDateDay.text)+String(arrivalDateMonth.text)+String(arrivalDateYear.text);
    trace(arrivalDate);
    arrivalDate = Date.parse(Number(arrivalDate));
    trace(arrivalDate);

The first trace will show the date like "ddMMyyyy", but after the parse I simply get NaN. I also tried trace(Number(arrivalDate));]

The reason why I want to be able to parse the date is so I can calculate the number of days apart from two dates.

Thanks, Peter

like image 874
Peter Stuart Avatar asked Nov 18 '25 10:11

Peter Stuart


1 Answers

You need to pass a supported format to Date.parse

From here :

Other supported formats include the following (you can include partial representations of these formats; that is, just the month, day, and year):

 MM/DD/YYYY HH:MM:SS TZD
 HH:MM:SS TZD Day Mon/DD/YYYY 
 Mon DD YYYY HH:MM:SS TZD
 Day Mon DD HH:MM:SS TZD YYYY
 Day DD Mon HH:MM:SS TZD YYYY
 Mon/DD/YYYY HH:MM:SS TZD
 YYYY/MM/DD HH:MM:SS TZD

As the documentation states you can leave out the hour minute second parts and just use day month year. Right now you are passing in the day, month and year with no spaces between.

like image 73
Barış Uşaklı Avatar answered Nov 20 '25 17:11

Barış Uşaklı



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!