I have a Django 1.6 project with the following relevant settings:
TIME_ZONE = 'America/Los_Angeles'
TIME_FORMAT = 'Hi'
DATE_FORMAT = 'Y M d'
DATETIME_FORMAT = '%s %s e' % (DATE_FORMAT, TIME_FORMAT)
USE_TZ = True
USE_L10N = False
I have an object called session
with a datetime field called start
.
>>> session.start
datetime.datetime(2014, 6, 7, 15, 0, tzinfo=<UTC>)
I want to display that datetime in the project's local timezone,
>>> from django.utils import timezone
>>> timezone.localtime(session.start)
datetime.datetime(2014, 6, 7, 8, 0, tzinfo=<LocalTimezone>)
So far so good. Now I want that local datetime to be displayed as a unicode string.
>>> str(timezone.localtime(session.start))
'2014-06-07 08:00:00-07:00'
My problem is that, instead of -07:00
I want the timezone to be displayed as PDT
. How can I change this?
Ideally I just want to convert the local datetime to a unicode string using the format specified in DATETIME_FORMAT
. The documentation for date format strings says that e
"could be in any format, or might return an empty string, depending on the datetime" but it does not suggest how I might specify what format I want.