Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format dateTime in django template?

That:

{{ wpis.entry.lastChangeDate|date:"D d M Y" }} 

gives me (why?):

2009-07-24 21:45:38.986156  

and i don't know how to skip fraction part...

In my model i have:

addedDate = models.DateTimeField(default=datetime.now) 
like image 914
IProblemFactory Avatar asked Jul 24 '09 21:07

IProblemFactory


People also ask

How do I set date format in Django?

Python django format date dd/mm/yyyy And, because the format is dd/mm/yyyy, we must use a slash to separate the date, month and year. To separate the day from the month and the month from the year in a date notation we use DateSeparator.

How do I change the date format in Python?

Use datetime. strftime(format) to convert a datetime object into a string as per the corresponding format . The format codes are standard directives for mentioning in which format you want to represent datetime. For example, the %d-%m-%Y %H:%M:%S codes convert date to dd-mm-yyyy hh:mm:ss format.

Can you use JavaScript in Django template?

Adding JavaScript to Our Django TemplateWe can add JavaScript to our template using an inline <script> tag or an external JavaScript file. Let's create a app. js file, put it in a js folder that you need to create in the static folder of your application.


1 Answers

This is exactly what you want. Try this:

{{ wpis.entry.lastChangeDate|date:'Y-m-d H:i' }} 
like image 117
Rockystech Avatar answered Sep 24 '22 12:09

Rockystech