Flex "Verbal Month" date

Hi All,

If you are working with Adobe flex, you probably know that the framework does not have a function such as DateTime.Now().ToString().

Because of that, displaying a friendly date to the user is impossible unless you write a small extension to the getDate() function in flex.

This is the way to go

 1: var todayDate:String = "";
 2:
 3: private function INIT():void{
 4:     getCurrentDate();
 5: }
 6:
 7: private var monthLabels:Array = new Array("Jan",
 8:                                           "Feb",
 9:                                           "Mar",
 10:                                           "Apr",
 11:                                           "May",
 12:                                           "Jun",
 13:                                           "Jul",
 14:                                           "Aug",
 15:                                           "Sep",
 16:                                           "Oct",
 17:                                           "Nov",
 18:                                           "Dec");
 19:
 20: private function getCurrentDate():void{
 21:     var date:Date = new Date();
 22:     todayDate = date.getDate().toString() + " " + monthLabels[date.getMonth()].toString() + " " + date.getFullYear().toString();
 23:     datePickerButton.label=todayDate;
 24: }

That’s it, it’s that easy to get a date from flex.

You can of course extend it some more in order to get the day.

Submit to Hacker News

[NOTE] This post has been imported to Hugo from a Wordpress blog. It may be broken, missing images, code snippets or other information.

[NOTE] updated March 24, 2009. It's 3597 days old . This article may have outdated content.