I am having that arcgis rest server bug where the attribute table and the attribute inspector show the dates as one day earlier. I found a possible solution on the web but there is an error in the following line because the attribute inspector has no "form" property. Is there any way to get around this? Thanks

error in this line

var formItems:* = editor.attributeInspector.form.getChildren();

/ Place the following code below the function populateEditor

private var dateFormatter:DateFormatter = new DateFormatter();

private const newDateFormat:String = “DD/MM/YYYY”;

private function attributeInspector_showFeatureHandler(event:AttributeInspectorEvent):void { formatDateFieldDisplay(event); } private function attributeInspector_updateFeatureHandler(event:AttributeInspectorEvent):void { formatDateFieldDisplay(event); } private function formatDateFieldDisplay(event:AttributeInspectorEvent):void { if(!(event.featureLayer && event.feature && event.feature.attributes)) return; // This ensures that we only validate when we are working at a field level (not an AttributeInspector level) if(event.field) { if(event.field.type == Field.TYPE_DATE) { if(event.newValue) // If it comes exclusively from an update … format the display { // Change the date format as desired event.target.formatString = newDateFormat; } } } else if(event.type.toLowerCase() == “showfeature”) { var formItems:* = editor.attributeInspector.form.getChildren();

  // Loop items and trigger update event
  for (var i:Number = 0; i < formItems.length; i++)
     if(formItems[i].data && formItems[i].data is Field)
        var field:Field = formItems[i].data;
        if(field.type == Field.TYPE_DATE &&
           field.name in event.feature.attributes &&    
           var event:AttributeInspectorEvent = new AttributeInspectorEvent(“updateFeature”,
           var formItem:* = formItems[i].getChildren();
           if(formItem && formItem.length > 0)

} }

// This function should be in a separate util file to be reused if necessary by other classes. // This function comes with the ArcGIS Viewer for Flex 2.4. // If Esri updates this function so should the developer. 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;
     return dateFormatter.error;

} else { return date.toLocaleString(); } }

Source: http://gisengineering.blogspot.co.nz/2011_09_01_archive.html


Perhaps your locale is several hours behind what i assume is the UTC date that you were hoping for. You could try removing the toLocaleString function, or try parsing the date with a function that removes the time offset

              public static function removeOffset(date:Date):Date{
                 var offset:Number = date.getTimezoneOffset() * 60 * 1000;
                 var localDate:Date = new Date(date.getTime() - offsetMilliseconds);
                 return localDate;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.