Home Tutorial Flex Flex4 Components DateFormatter in Flex4

 
 

Share on Google+Share on Google+
DateFormatter in Flex4
Posted on: June 2, 2010 at 12:00 AM
Advertisement
The DateFormatter class formats a date in month, day, year format.

DateFormatter in Flex4:

The DateFormatter class formats a date in month, day, year format. You can set the formatString property for date formatter. If an error occurs this error is saved to the error property. The error property has two types of error values: Invalid value, Invalid format. The tag of DateFormatter is <mx:DateFormatter>. You will be declare a formatter in <fx:Declarations> tag.

Example:

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:mx="library://ns.adobe.com/flex/mx"

minWidth="955" minHeight="600">

<fx:Script>

<![CDATA[

import mx.events.ValidationResultEvent;

private var result:ValidationResultEvent;

private function checkFormat():void

{

result = dateValidate.validate();

if (result.type==ValidationResultEvent.VALID) {

dateValue.text=dateFormatter.format(datetxt.text);

}

else {

dateValue.text= "Invalid Date";

}

}

]]>

</fx:Script>

<fx:Declarations>

<mx:DateFormatter id="dateFormatter" formatString="month: MM,

 day: DD, year: YYYY"/>

<mx:DateValidator id="dateValidate" source="{datetxt}" property="text"

 inputFormat="mm/dd/yyyy"/>

</fx:Declarations>

<s:Panel title="DateFormatter Example" width="548">

<mx:Form width="546" backgroundColor="#096465">

<mx:FormItem label="Enter Date (mm/dd/yyyy):" color="#FFFFFF"

 fontFamily="verdana">

<s:TextInput id="datetxt" color="#000000" fontFamily="verdana"/>

</mx:FormItem>

<mx:FormItem label="Formatted date: " color="#FFFFFF" fontFamily="verdana">

<s:Label id="dateValue" color="#FFFFFF" fontFamily="verdana"/>

</mx:FormItem>

<mx:FormItem>

<s:Button label="Format" click="checkFormat();"/>

</mx:FormItem>

</mx:Form>

</s:Panel>

</s:Application>

Output:

Running Application:

To view this page ensure that Adobe Flash Player version 10.0.0 or greater is installed.

Download this code

Advertisement

Related Tags for DateFormatter in Flex4:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 2, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com