private function msToDate(ms:Number, dateFormat:String, useUTC:Boolean):String { var date:Date = new Date(ms); if (date.milliseconds == 999) // workaround for REST bug { date.milliseconds++; } if (useUTC) { date.minutes += date.timezoneOffset; } if (dateFormat) { dateFormatter.formatString = dateFormat; var result:String = dateFormatter.format(date); if (result) { return result; } else { return dateFormatter.error; } } else { return date.toLocaleString(); } }
I'm facing a very similar problem but can't seem to figure it out. It sounds like you solved this issue. Can you please post some code?
My situation may differ slightly as my date info is coming from a Table included in the map service (via QueryTask/Query). I can query it and get the long integer / ticks since epoch value from the returned FeatureSet Graphic, but like you, I can't seem to check the type on the attribute/field that contains it. The fact that the API doesn't do some checking of the attribute data type prior to displaying it's "value" seems like a major miss to me as the seconds (or whatever time measurement it uses) count since Jan 1, 1970 doesn't mean anything to any human. Also, capturing it manually is not very straight-forward as you can't get your hands on the specific Field in the Graphic's attribute collection to check the type.
I tried to do that by something like this...
for each (var field:Field in graphic.attributes) - this line results in a conversion error.
{
if (field.type == "esriFieldTypeDate")
{
//Convert to something humans understand...
Please help!
Kelly Hutchins I've seen you post other comments on similar issues. Do you have any recommendations?
Lance,
If you are using a QueryTask then the result of that is a FeatureSet and the featureset will have a fields property and there you will be able to determine the field type. The reasoning behind the ArcGIS Server and/or web api teams not automatically assigning a date format is this would lock developers into only have the date in that specific format instead of being able to choose the format that they want.
Yep. Robert's right. I ended up doing this in my code.
private function featureSelectionComplete(event:FeatureLayerEvent):void
{
for each (var field:Field in event.target.layerDetails.fields)
{
if (field.type == Field.TYPE_DATE)
{
//TODO - handle date field here
}
}
}
Thanks for the explanation and the help. I was able to resolve my issue and am seeing dates formatted correctly.