def filter_formatdate(val, format):
 encoding = locale.getpreferredencoding()
 if (not isinstance(val, (datetime, date, time))):
  return val
 return native_str_to_text(val.strftime(text_to_native_str(format, encoding=encoding)), encoding=encoding)

def filter_formatdate ( val , format ) : encoding = locale . getpreferredencoding ( ) if ( not isinstance ( val , ( datetime , date , time ) ) ) : return val return native_str_to_text ( val . strftime ( text_to_native_str ( format , encoding = encoding ) ) , encoding = encoding )
returns a string representation of a datetime object according to format string .