How to get the Current Date Time Formatted in Flex

Khattab picture Khattab · Oct 30, 2010 · Viewed 36.9k times · Source

I'm trying to get the current date time in Flex/AIR?

Answer

Khattab picture Khattab · Apr 26, 2011

To get the current date time, just create a new Date object with no values into the constructor, like this:

    var CurrentDateTime:Date = new Date();

Formatting it depends on how you want to format it; here is one option:

private function CurrentDateTimeString():String
{               
    var CurrentDateTime:Date = new Date();
    var CurrentDF:DateFormatter = new DateFormatter();
    CurrentDF.formatString = "MM/DD/YY LL:NN:SS A"
    var DateTimeString:String = CurrentDF.format(CurrentDateTime);
    return DateTimeString;
}