Change format fo date shown in dateField

So in Flex if we want user to select a date, we have DateField component that is made just for that.

In it’s default state the DateField will show the selected date in format month/day/year (for example 12/31/2008). If we want to change the way Flex shows the selected date we can do that by changing the formatString in DateField component. For month we use MM, for days we use DD and for year we use YYYY. So default value for formatString is MM/DD/YYYY. If we want to have fullstops instead of slashes to seperate day, month and year we do formatString=”MM.DD.YYYY”.

In the application above, we have one arrayCollection (id=formatStrings) with values for dateFormat string. We also use a dropdown menu, that let’s us change the formatString of the DateField. We set the dataProvider of our dropdown (ComboBox component) and set it to our arrayCollection – formatString.

For DateField we say that we want our formatString be the selected row of our drop down menu with formatString=”{comboFormats.selectedItem}”, and thus we can see how the date changes when we select a different row in the drop down menu.

Since we want DateField to have a selected date at the application launch we put selectedDate=”{new Date()}”, which selects today’s date.

You can also see that we set the firstDayOfWeek=”1″, this line tells DateField component to put Monday as the first day in calendar view when we want to select a specific day. Default value of firstDayOfWeek is 0-Sunday, so 1-Monday, 2-Tuesday, 3-Wednesday, 4-Thursday, 5-Friday, 6-Saturday.

The source code of application can be found below.


, ,

  1. Leave a comment

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: