1

I want to get date in this format %d-%m-%Y" in following code:

from django.utils.timezone import localtime, now
from freezegun import freeze_time
.....
    @freeze_time("12-02-2012")
    def setUp(self):
        self.current_date = localtime(now()).date()

In my settings.py I have these settings:

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Dhaka'

USE_I18N = True

USE_L10N = True

USE_TZ = True

DATE_INPUT_FORMATS = ("%d-%m-%Y", )
DATE_FORMAT = ("%d-%m-%Y", )

But now I am getting date 2012-12-02. So what is the correct way to get date in %d-%m-%Y format in test client.

pyprism
  • 2,928
  • 10
  • 46
  • 85
  • Closely related: https://stackoverflow.com/questions/3617804/django-use-of-date-format-datetime-format-time-format-in-settings-py – zwol Jan 03 '17 at 14:09
  • The object returned by `django.utils.timezone.localtime` appears to be a plain old [`datetime.datetime`](https://docs.python.org/3/library/datetime.html#datetime-objects) from the Python standard library. Its `date` method returns a `datetime.date`. The formatting, therefore, is happening in code you have not shown. – zwol Jan 03 '17 at 14:11

0 Answers0