js使用方法:
var now = new Date(1500541859000);
var year = now.getFullYear(),
month = now.getMonth() + 1,
date = now.getDate(),
hour = now.getHours(),
minute = now.getMinutes(),
second = now.getSeconds();
function p(s) {
return s < 10 ? '0' + s: s;
}
var timeFormat = year + "-" + p(month) + "-" + p(date) + " " + p(hour) + ":" + p(minute) + ":" + p(second);
jQuery使用方法:
$.myMethode = {
//定义一个方法formatTime
formatTime: function(time){
var now= new Date(parseInt(time));
var year = now.getFullYear(),
month = now.getMonth() + 1,
date = now.getDate(),
hour = now.getHours(),
minute = now.getMinutes(),
second = now.getSeconds();
timeFormat = year + "-" + $.numCheck.p(month) + "-" + $.numCheck.p(date) + " " + $.numCheck.p(hour) + ":" + $.numCheck.p(minute) + ":" + $.numCheck.p(second);
return timeFormat;
}
}
$.numCheck = {
//定义一个方法
p: function(s){
return s < 10 ? '0' + s: s;
}
}
// 调用方法
var formateTime = $.myMethode.formatTime(1500541859000);