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

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

Avi Tzurel

My name is Avi Tzurel. I'm a professional web developer from Israel. I spend most of my day developing both web products and RIA applications as well as imparting my experience onto others. I speak, teach and write about my passions, and develop applications according to what I preach. I specialize in Flex, Adobe Air, HTML, XHTML, Javascript, jQuery and other Javascript libraries, on the server side I do .net along side with Ruby on Rails. You can connect with me on Twitter or email me through the contact page on this blog.

  • Share/Bookmark
Posted Tuesday, March 24th, 2009 under Flex.

Leave a Reply