Mihkel L.
Mihkel L.

Reputation: 1573

Datetime In Django Template

From this answer

In my template i need to make 1255992517000 to an date-time. i tried {{note.created|date:"U"}} and 1255992517000|date:"U" but it didn't work. How to get it to work? From django docs one can see it should work, but how?

Upvotes: 0

Views: 2301

Answers (2)

Matthew Schinckel
Matthew Schinckel

Reputation: 35599

You are misunderstanding what the {{ value|date }} filter is capable of doing. It will not turn an integer into a date object, you must be passing it an existing date object.

You could write your own template filter to convert the value into a date first.

Upvotes: 3

Chris McKinnel
Chris McKinnel

Reputation: 15082

Applying the filter date:"U" is telling the template to display seconds since the Unix Epoch (January 1 1970 00:00:00 UTC).

If you want to display a readable date / time, try something like:

{{ note.created|date:"D d M Y" }}

Upvotes: 1

Related Questions