Django: how to get format date in views?

The django.utils.formats module is what you’re looking for. The only reference I could find in the docs was in the Django 1.2 release notes.

Remember that the localisation will only work if the USE_L10N setting is True. You can use the date_format as follows.

from datetime import datetime
from django.utils import formats
date_joined = datetime.now()
formatted_datetime = formats.date_format(date_joined, "SHORT_DATETIME_FORMAT")

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)