Jq 转换日期对象 /Date(1620699801000)/ 为正常时间
https://blog.csdn.net/honeycandys/article/details/80679913
function changeDateFormat(val) {
if (val != null) {
var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
//月份为0-11所以+1,月份小于10补个0
var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
var dd = date.getFullYear() + "-" + month + "-" + currentDate + " " + hour + ":" + minute + ":" + second;
return dd;
}
}
————————————————
版权声明:本文为CSDN博主「尤加利与海」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/honeycandys/article/details/80679913
function dateToStr(dateTime, fmt) {
if (dateTime != null && dateTime != "" && dateTime != undefined) {
var datetime = new Date(parseInt(dateTime.replace("/Date(", "").replace(")/", ""), 10));
if (parseInt(datetime) == datetime) {
if (datetime.length == 10) {
datetime = parseInt(datetime) * 1000;
} else if (datetime.length == 13) {
datetime = parseInt(datetime);
}
}
datetime = new Date(datetime);
var o = {
"M+": datetime.getMonth() + 1, //月份
"d+": datetime.getDate(), //日
"h+": datetime.getHours(), //小时
"m+": datetime.getMinutes(), //分
"s+": datetime.getSeconds(), //秒
"q+": Math.floor((datetime.getMonth() + 3) / 3), //季度
"S": datetime.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (datetime.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
return "";
}