Display timestamp in django template

前端 未结 5 1092
太阳男子
太阳男子 2020-12-16 13:26

I need to display timestamp of a post with in django template. The timestamp would be like:

\"timestamp\":1337453263939 in milli seconds

I

5条回答
  •  -上瘾入骨i
    2020-12-16 14:20

    Just write a custom filter that converts your timestamp string to a datetime object. Then you can either further process it into something readable (a string representing your time) and return it to your template or just return a python datetime object and use django's date filter.

    So you could have something like this {{ timestamp_string|convert_to_datetime|date:'D d M Y' }}

    More on this subject at: https://docs.djangoproject.com/en/dev/howto/custom-template-tags/

提交回复
热议问题