用vue {{}}方式 显示的Data字符串 是UTC
SQL Server DateTIme => “YYYY-MM-DD hh:mm:ss.xxx”
function dateToMssql(datetime) {
let year = datetime.getFullYear(),
month = datetime.getMonth() + 1,
date = datetime.getDate(),
hour = datetime.getHours(),
minutes = datetime.getMinutes(),
second = datetime.getSeconds(),
ms = datetime.getMilliseconds();
if (month < 10) {
month = "0" + month;
}
if (date < 10) {
date = "0" + date;
}
if (hour < 10) {
hour = "0" + hour;
}
if (minutes < 10) {
minutes = "0" + minutes;
}
if (second < 10) {
second = "0" + second;
}
return (
year +
"-" +
month +
"-" +
date +
" " +
hour +
":" +
minutes +
":" +
second +
"." +
ms
);
}
更加通用的方法
function dateFormat(fmt, date) {
let ret;
const opt = {
"Y+": date.getFullYear().toString(), // 年
"m+": (date.getMonth() + 1).toString(), // 月
"d+": date.getDate().toString(), // 日
"H+": date.getHours().toString(), // 时
"M+": date.getMinutes().toString(), // 分
"S+": date.getSeconds().toString(), // 秒
"q+": Math.floor((date.getMonth() + 3) / 3), //季度
"s": date.getMilliseconds() //毫秒
};
for (let k in opt) {
ret = new RegExp("(" + k + ")").exec(fmt);
if (ret) {
fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
};
};
return fmt;
}