开发者

How to get the Current Date Time Formatted in Flex

I'm trying to get the current da开发者_StackOverflowte time in Flex/AIR?


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;
}


currentTime = new Date();

From : http://livedocs.adobe.com/flex/3/html/help.html?content=08_Dates_and_times_5.html

and

http://docs.huihoo.com/flex/4/Date.html


private function CurrentDateTimeString():String
{

   var CurrentDateTime:Date = new Date();


   var DateString:String = CurrentDateTime.getMonth().toString()+ "/"+CurrentDateTime.getDate().toString() +"/"+CurrentDateTime.getFullYear().toString();
   var TimeString:String = CurrentDateTime.getHours().toString()+ ":"+ doubleDigitFormat(CurrentDateTime.getMinutes());
   var DateTimeString:String = DateString + " " + TimeString;
   return DateTimeString;
  }

function doubleDigitFormat(num:uint):String 
{

   if(num < 10) {
    return ("0" + num);
   }
   return num.toString();

  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜