This content has been marked as final. Show 4 replies
"cicero111" <firstname.lastname@example.org> wrote in message
> Is it possible to simply parse a date string back to a date object which
> formatted with a date formatter. I don't want to write an own parser.
> var df:DateFormatter = new DateFormatter();
> df.FormatString ="DD.MM.YYYY";
> var myCurrentDate:Date = new Date();
> myCurrentDateString:String = df.Format(myCurrentDate); // e.g "17.02.2009"
> var myNewDate:Date = xxx.xxx(myCurrentDateString);
> Some ideas for xxx.xxx?
> I hope there is something simple like
> myNewDate:Date = df.parse(myCurrentDateString);
> Date.parse() only seems to parse a non-formatted date string.
I think DateField has a function that does this. You may want to go through
its API reference in detail.
Trying to convert a string like "17.02.2009" fails on my system because Date() is using my local date settings (like: 02/17/2009).
So you need to change the formatter's formatString to match the local settings, then use THAT string to convert to a Date() object.
Here are some examples to help you; play around and you'll see what's happening:
It work's fine with DateField, but in ActionScript I found nothing appropriate.
I didnot get your statement - "It work's fine with DateField, but in ActionScript I found nothing appropriate."
try once using following:
public static function stringToDate(valueString:String, inputFormat:String):Date
var dob:Date = DateField.stringToDate("06/30/2005", "MM/DD/YYYY");
public static function dateToString(value:Date, outputFormat:String):String
var todaysDate:String = DateField.dateToString(new Date(), "MM/DD/YYYY");
DateField is available in the package mx.controls
and as these functions are static, you can use them directly.
xxx.xxx -- DateField.stringToDate
hope it is useful.