Select to view content in your preferred language

DateFormatter for esriFieldTypeDate

4991
5
08-07-2012 10:38 AM
NaveenKatta
Deactivated User
Hi All,

I excuted spatial query and got the results, In that results one column is esriFieldTypeDate and that value is 1131321600000.
I try to convert it to MM/DD/YYYY using DateFormatter  but It is not working. Any idea??

Thanks,
Naveen
Tags (2)
0 Kudos
5 Replies
NaveenKatta
Deactivated User
I got the solution:

var sDate:Date = new Date(dateString);
var s2:String=DateField.dateToString(sDate,"MM/DD/YYYY ")
0 Kudos
LanceGoens
Occasional Contributor

Can you show more of your code? I have a similar issue from an attribute query. The Graphic(s) contained in the returned FeatureSet contain attributes of esriFieldTypeDate but it's not displaying in any known date format. If your code above works, how are you detecting that the attribute is of the date format?

0 Kudos
PierreLarondelle
Regular Contributor

Hello,

Here's the way I'm dealing the date format returned in esriFieldTypeDate type in an ItemRenderer :

data.datereservon = the value in esriFieldTypeDate from the FeatureLayer

dfData = Datefield in ItemRenderer.

It's certainly not the most elegant way of coding it  but it gives complete control on the final "look" of your date.

Hope it helps ...

protected function parseDateResOn():void
{
YourDateFormatterID.formatString = "DD/MM/YYYY";
var dateOn:Date = new Date(data.datereservon);
var dayFromDateStringed:String = dateOn.date.toString();
var monthFromDateStringed:String = dateOn.month.toString();
var yearFromDateStringed:String = dateOn.fullYear.toString();
var dateResOn:String = dayFromDateStringed + "/" + monthFromDateStringed + "/" + yearFromDateStringed;
dfData.text = dateResOn;
//data.datereservon = dateResOn;
}
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Pierre,

  Here is another way:

import spark.formatters.DateTimeFormatter;

var dateFormatter:DateTimeFormatter = new DateTimeFormatter();

var dateOn:Date = new Date(data.datereservon);

dateFormatter.dateTimePattern = "DD/MM/YYYY";

dfData.text = dateFormatter.format(dateOn);

0 Kudos
PierreLarondelle
Regular Contributor

Short and efficient, thanks a lot Robert for sharing the best practices in Flex coding !

Pierre.

0 Kudos