def format_date_time(request, value, format='shortdatetime'):
 if (not isinstance(value, datetime.datetime)):
  if isinstance(value, datetime.date):
   value = datetime.datetime.combine(value, datetime.datetime.min.time())
  else:
   raise ValueError
 default_tz = timezone(settings.TIME_ZONE)
 tzvalue = default_tz.localize(value)
 user = request.user
 try:
  if (user.is_authenticated() and user.timezone):
   user_tz = timezone(user.timezone)
   tzvalue = user_tz.normalize(tzvalue.astimezone(user_tz))
 except AttributeError:
  pass
 locale = _babel_locale(_get_request_locale(request))
 try:
  formatted = format_date_value(value, tzvalue, locale, format)
 except KeyError:
  formatted = format_date_value(value, tzvalue, _babel_locale(settings.LANGUAGE_CODE), format)
 return (formatted, tzvalue)

def format_date_time ( request , value , format = 'shortdatetime' ) : if ( not isinstance ( value , datetime . datetime ) ) : if isinstance ( value , datetime . date ) : value = datetime . datetime . combine ( value , datetime . datetime . min . time ( ) ) else : raise ValueError default_tz = timezone ( settings . TIME_ZONE ) tzvalue = default_tz . localize ( value ) user = request . user try : if ( user . is_authenticated ( ) and user . timezone ) : user_tz = timezone ( user . timezone ) tzvalue = user_tz . normalize ( tzvalue . astimezone ( user_tz ) ) except AttributeError : pass locale = _babel_locale ( _get_request_locale ( request ) ) try : formatted = format_date_value ( value , tzvalue , locale , format ) except KeyError : formatted = format_date_value ( value , tzvalue , _babel_locale ( settings . LANGUAGE_CODE ) , format ) return ( formatted , tzvalue )
returns date/time formatted using babels locale settings .