美文网首页
JS将时间戳集合转换为显示时间

JS将时间戳集合转换为显示时间

作者: 京城小白君 | 来源:发表于2018-01-05 10:12 被阅读0次

js写法:
//携带具体时间(年月日,时分秒)
function getLocalTime(nS) {
return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
}

//不带时间(年月日)
function getArticleTime(nS) {
var date = new Date(parseInt(nS) * 1000);
return [ date.getFullYear(), date.getMonth() + 1, date.getDate() ].join('-');
}

//定义变量,获取集合的长度
var build = $(".bal_con_list_right2 span").length;
//循环执行js
for ( var i = 0; i < build; i++) {
   //获取页面显示的时间戳
   var builds = $(".build_answer_dateline_" + i).text();
   //调用js进行就改并赋值会原位置
   $(".build_answer_dateline_" + i).text(getArticleTime(builds));
}

html页面写法:
<div class="bal_con_list_right2">
   <c:forEach items="携带时间戳的集合" val="别名" varStatus="index">
       <span calss="build_answer_dateline_${index.index}" >${别名.时间戳}</span>
    </c:forEach>
</div>
注:加载页面的时候执行js部分,

相关文章

网友评论

      本文标题:JS将时间戳集合转换为显示时间

      本文链接:https://www.haomeiwen.com/subject/hnejnxtx.html