2017-05-05 2 views
0

API에서 오랜 시간 형식으로 오는 모든 항목에 대한 시간 값이 있습니다. 사람이 읽을 수있는 형식으로 변환하려고합니다.django templtes 목록에서 적절한 시간으로 긴 형식 시간 변환?

내 API 값은 다음과 같습니다 -

내가 장고 template.I에 사람이 읽을 수있는 forn createdAt을 변환 할 수있는 방법을 지금
"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": "[email protected]", 
     "profileImage": "", 
     "profileImageThumbnail": "", 
     "isfollow": false 
     }, 
     "image": null, 
     "createdAt": 1493978312000 
    } 

이와 내가 이것을 달성 할 수있는 방법 tables.So에 표시 할 forloop을 uaing 같은 많은 값이 .

+0

이 작업'가 {{createdAt | 날짜 : "D d 개의 M의 Y는"}}'? – itzMEonTV

+0

@ L_S 시도하지 않았습니다. –

+1

@AbiWaqas 이것을 찾으십니까? http://stackoverflow.com/a/14708395/7724457 –

답변

0

django에서 타임 스탬프를 사람이 읽을 수있는 형식으로 구문 분석하는 simple tag을 작성하여이 작업을 수행 할 수 있습니다.

{% 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) 

는 또는 자바 스크립트에서 하찮게을 수행

<span> 
    <script>document.write(Date({{ createdAt }}))</script> 
</span> 
+0

필터는 아마도 기본'date'가 함께 묶일 수 있기 때문에 더 나을 것입니다. – Anonymous

관련 문제