1 Reply Latest reply on Feb 27, 2008 7:50 AM by Domtar

    DateFormatter bug

      Apparently the AM/PM indicator in the DateBase.as class is never initialized so it returns null instead of "AM" or "PM". This results in strings like "6/24/08 12:03 null" being returned when the A is in the format string. The workaround is to explicitly set the _timeOfDay array on the DateBase class before using the DateFormatter. The following is used as an item renderer in a grid to convert millis into a readable date. Remove the "DateBase.timeOfDay = ["AM", "PM"];" call before the formatter to see the bug...

      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml"
      xmlns="*" verticalScrollPolicy="off" horizontalScrollPolicy="off" >
      import mx.utils.ObjectProxy;
      import mx.formatters.DateBase;
      import mx.formatters.DateFormatter;

      public function getDate(millis:Number):ObjectProxy {
      DateBase.timeOfDay = ["AM", "PM"];
      var fmt:DateFormatter = new DateFormatter();
      fmt.formatString = "MM/DD/YYYY LL:NN A";
      rdate.text = fmt.format(new Date(millis));
      return new ObjectProxy(rdate.text);
      <mx:Label id="rdate" text="{getDate(data.timestamp)}" styleName="dateItemRenderer"/>