At Django's models.py When using timezone.now () instead of datetime.now ()
date = models.DateTimeField ('date', default = timezone.now ())
Then the format is 2020-12-08 21:12:24.333404+00:00 become that way.
When you want to express something like 12/08/20 on a web application
date = models.DateTimeField(datetime.now().strftime('%m%d%y %H:%M'))
If you do
ValidationError [u"'12/08/2020' value has an invalid date format. It must be in YYYY-MM-DD format."]
Error is displayed.
When displaying the date acquired in html, you can specify the format as follows.
<div>{{ item.ans_date|date:"m/d/y H:i" }}</div>
In this case, it will be displayed as "01/01/20 02:41" .
In addition, if you want to use 12h notation, do not add 0 at the beginning, or display the year in 4 digits, refer to the following page. https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#date
Have a good Django life!
Recommended Posts