// js 格式化时间戳,显示格式 yyyy-MM-dd HH:mm:ss 。输入的 timestamp 例如 1510452672000
function formatTimestamp( timestamp ) {
var dateObj = new Date( timestamp );
var year = dateObj.getYear() + 1900;
var month = dateObj.getMonth() + 1;
var theDate = dateObj.getDate();
var hour = dateObj.getHours();
var minute = dateObj.getMinutes();
var second = dateObj.getSeconds();
return year +"-"+ month +"-" + theDate + " "+ hour +":"+ minute +":"+ second;
}
function formatTimestamp( timestamp ) {
var dateObj = new Date( timestamp );
var year = dateObj.getYear() + 1900;
var month = dateObj.getMonth() + 1;
var theDate = dateObj.getDate();
var hour = dateObj.getHours();
var minute = dateObj.getMinutes();
var second = dateObj.getSeconds();
return year +"-"+ month +"-" + theDate + " "+ hour +":"+ minute +":"+ second;
}
本文介绍了一个JavaScript函数,用于将时间戳格式化为更易读的形式,即'yyyy-MM-dd HH:mm:ss'。此函数适用于前端开发场景,可以方便地将UNIX时间戳转换成日期和时间字符串。
485

被折叠的 条评论
为什么被折叠?



