js 中 时间戳转换为时间
2013-02-26 11:16 freefei 阅读(350) 评论(0) 编辑 收藏 举报
切记 php的时间戳 要乘以1000
changeTimeFormat(value.ctime*1000)
[js]
function changeTimeFormat(time) {
var date = new Date(time);
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var hh = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var mm = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
return date.getFullYear() + "-" + month + "-" + currentDate+" "+hh + ":" + mm;
//返回格式:yyyy-MM-dd hh:mm
}
[/js]