def FormatDateString(dt, time=True):
   """Formats a DateTime object into a string for display.  If dt is not
      a DateTime, then the empty string is returned.
      Parameters:
         * dt    - An instance of DateTime.DateTime
         * time  - If True, displays the time. If False, only the date is
                   displayed.
      Returns:
         A formatted time string, or '' if the input cannot be parsed.
   """
   if hasattr(dt, 'isoformat'):
      datestr = dt.isoformat().replace('T', ' ')
      return datestr[:time and 19 or 10]
   else:
      return ''