How to get the Current Date Time Formatted in Flex
37,067
Solution 1
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;
}
Solution 2
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
Solution 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();
}
Author by
Khattab
I'm a Software Engineer with a passion for new technologies, I've worked on a lot of different projects, from Windows Mobile to iOS and from Web (HTML, ASP.NET, Flex, Webservices) to Windows (Services and Apps). Love GIS! Like a challenge every now and then.
Updated on July 24, 2022Comments
-
Khattab almost 2 years
I'm trying to get the current date time in Flex/AIR?
-
Khattab over 13 yearsThanks, I was trying to find the below, your links helped:
-
JeffryHouser over 11 yearsWhile I'm glad you found your solution; this does not actually answer your question; but rather the question of "how do I format the current date"
-
Khattab over 11 yearsTrue, but back then I probably didn't even know what I was looking for! I'll see if I can modify the title.