0

I have a time value for every entry coming in long time format from API.So i want to convert it into human readable form.

my API values are:-

"data": [
    {
      "id": 33613,
      "virtualNewsId": 30513,
      "newsCommentText": "@39586!~~!Abhay_raj_singh_chauhan!~~!Abhay%20Raj%20%20!>>! @39586!~~!Abhay_raj_singh_chauhan!~~!Abhay%20Raj%20%20!>>!",
      "user": {
        "id": 39561,
        "name": "chatuser",
        "username": "chatuser",
        "email": "chatuser@mail.com",
        "profileImage": "",
        "profileImageThumbnail": "",
        "isfollow": false
      },
      "image": null,
      "createdAt": 1493978312000
    }

now how can i convert createdAt human readable forn in django template.I have many values like this and uaing forloop to display on tables.So how can i achieve this.

Abi Waqas
  • 299
  • 1
  • 13

1 Answers1

0

You can do this in django by writing a simple tag that parses your timestamp into a human readable format.

{% parsetimestamp createdAt %}

import datetime
from django import template

register = template.Library()

@register.simple_tag(name='parsetimestamp')
def parser(value):
    return datetime.datetime.fromtimestamp(value/1000)

Or do it trivially in Javascript:

<span>
   <script>document.write(Date({{ createdAt }}))</script>
</span>
Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139