js和php时间戳的问题

js的时间戳是13位的,而php是10位的。

所以在客户端收到后台的时间戳后需要进行转换 --> var timestamp = new date(timestamp * 1000);

以下是将时间戳转化为时间的函数

/**
将时间戳转化为时间
*/
function timestampToTime(timestamp) {
var date = new Date(timestamp);
Y = date.getFullYear() + '-';
M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
D = date.getDate() + ' ';
h = date.getHours() + ':';
m = date.getMinutes();
s = date.getSeconds();
return Y+M+D+h+m+s;
}

 

posted @ 2018-04-03 21:35  web_小隆  阅读(170)  评论(0编辑  收藏  举报