【原创】关于jquery实现格式化时间

时间:2025-02-24 19:04:56
//js格式化时间,参数jsonDate可以是后台数据
function jsonDateFormat(jsonDate) {
try {
var date = new Date(parseInt(jsonDate.replace("/Date(", "").replace(")/", ""), 10));
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
if (minutes < 10) {
minutes = "0" + minutes;
}
var seconds = date.getSeconds();
if (seconds < 10) {
seconds = "0" + seconds;
}
var milliseconds = date.getMilliseconds();
return date.getFullYear() + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;//这里可以根据需要只显示年、月、日
} catch (ex) {
return "";
}
}

格式化时间

//相关资源:js时间格式转换以及data对象总结
http://yk1688.blog.51cto.com/2000558/413970

本人才疏学浅,如果写的不对,欢迎园子中的朋友拍砖!