Avg. Rating 5.0

Problem

Need to convert data format as 01-01-2010 to 01-Jan-2010, because default date component gives only the dd/mm/yyyy

Solution

Created a custom component by extending to DateField.

Detailed explanation

How to use

<customComponent:CustomDateField />

Custom component for new formatted datefield
 

package customComponent
{
      import mx.controls.DateField;
      import mx.formatters.DateFormatter;

      public class CustomDateField extends DateField
      {
            public var isRequired:Boolean = false;
            public var caption:String;
            public var customDateFormat:DateFormatter;

          

            public function CustomDateField ()
            {               
                  super();
                  onCreateDate();
                  this.formatString = "DD-MMM-YYYY";
                  this.parseFunction = null;
                  this.editable = true;
                  this.labelFunction = onLabelFunction;
            }


            public function onCreateDate():void
            {
                  customDateFormat = new DateFormatter;
                  customDateFormat.formatString = "DD-MMM-YYYY";
            }
      

            private function onLabelFunction(date:Date):String

            {
                 return customDateFormat.format(date);
            }
      }
}

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes