Django Timezone Support Outside of Templates -


django's timezone-aware output apparently only applies when rendering template. there way same auto-conversion active timezone responses returning csv or json?

it seems underlying function called convert datetimes in templates django.utils.timezone.template_localtime(). right next in source utility function, localtime, looks like:

def localtime(value, timezone=none):     """     converts aware datetime.datetime local time.      local time defined current time zone, unless time zone     specified.     """     ... 

so perhaps following work:

from django.utils.timezone import localtime, get_current_timezone  ...  print localtime(obj.date_created, user.get_profile().timezone or get_current_timezone()) 

Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -