我正在尝试在Flex / AIR中获取当前日期时间?
答案 0 :(得分:25)
要获取当前日期时间,只需在构造函数中创建一个没有值的新Date对象,如下所示:
var CurrentDateTime:Date = new Date();
格式化取决于您希望如何格式化它;这是一个选择:
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;
}
答案 1 :(得分:6)
currentTime = new Date();
来自:http://livedocs.adobe.com/flex/3/html/help.html?content=08_Dates_and_times_5.html
和
答案 2 :(得分:3)
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();
}