Flex "Verbal Month" date

tweet! tweet this post subscribe! subscribe to RSS feed

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, its that easy to get a date from flex.

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

  • Tags:
tweet! tweet this post subscribe! subscribe to RSS feed

This theme was created by: Jeff Kreeftmeijer, Thank you!

 
Fork me on GitHub