1

我目前正在使用 instagram 的 API 来收集有关照片的 JSON 数据,并且我正在使用下划线模板来显示数据。我很难以简单的月/日/年格式打印日期(以 Unix 时间提供)。

<div class="mask">  
    <h2> <!-- Formatted date --> </h2>  
    <p>
         <% if (item.get('caption')) { %>
         <%= item.get('caption').text %>
         <% } %>
    </p>  
    <p><%= item.get('likes').count %> likes, <%= item.get('comments').count%> comments</p>  
</div>  
4

1 回答 1

1

Figured out what I needed to do! The date attribute was giving me a string, so after solving that using using Date() and parseInt() in conjunction with moment.js, I realized all I had to do was multiply the value by 1000 to give me the correct date. Hope this comes in handy for anyone using an API that provides dates as strings in unix time.

<h2> <%= moment(new Date(parseInt(item.get('created_time'))*1000)).format("MM-DD-YYYY")
%></h2>  
于 2013-10-25T18:49:57.850 回答