Select to view content in your preferred language

Date Field Question

586
2
06-06-2011 08:45 AM
AlexSanders
Frequent Contributor
I have a column that has a date field of mm/dd/yyyy.  When I publish this data to a map service, the date field changes to add i.e. Wed, Sep 30 2010 06:30 p.m.  

How can I change the date settings to not display the long form time format from my OS?

Alex
Tags (2)
0 Kudos
2 Replies
ReneRubalcava
Esri Frequent Contributor
You'll need a DateFormatter. Depending if you are using a LabelFunction or an ItemRenderer, you could return it a couple of ways, but it could look like this.
myGrid.labelFunction = labelFunction

private function labelFunction(item:Object, column:DataGridColumn):String
{
 var field:String = column.dataField;
 if ("Date" == field)
 {
  var d:Date = new Date(item[field]);
  return formatDate(d);
 }
 else
  // return some other stuff for other columns
}
private function formatDate(date:Date):String
{
 if (date)
 {
  var df:DateFormatter = new DateFormatter();
  df.formatString = "MM/DD/YYYY";
  return df.format(date);
 }
 else
  return "None";
}
0 Kudos
AlexSanders
Frequent Contributor
That worked perfectly thanks!
0 Kudos