Converting between dates and strings using the DateField class and methods in it,in Flex.

In DateField Class there are methods like dateToString() stringToDate() toDateString(). so by using these methods we can define our code.

First import the required package and class in it.

import mx.controls.DateField;

The following example explains the need:

var birthday:String = “16/10/1984”;

var birthdayDate:Date = DateField.stringToDate(birthday, “DD/MM/YYYY”);

labelbirthday.text=birthdayDate.toDateString();

<mx:Label id=”labelbirthday” />

Here first the string birthday is converted into Date using the method stringToDate() and then convert it into DateString using the method toDateString();.Thats all the label prints the birthday in string format as “Tue Oct 16 1984”.

Now its similar to convert a Date into String using the methos,dateToString().The below Example shows it.

var today:Date = new Date();

var todayString:String = DateField.dateToString(today, “DD/MM/YYYY”);
todayLabel.text = todayString;

Now the todayLabel get the today date in string.Thats it Enjoy the code.

Advertisements

One Response to Converting between dates and strings using the DateField class and methods in it,in Flex.

  1. Hey, nice tips. Perhaps I’ll buy a glass of beer to that man from that chat who told me to visit your site 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: