注:CST轉(zhuǎn)成GMT時(shí)間存在new Date()導(dǎo)致原時(shí)間會(huì)增加14h训措,所以在設(shè)置時(shí)間時(shí),需要-14h光羞。
function cstDateFormat(date, format) {
date = new Date(date);
date.setHours(date.getHours() - 14);
var dset = {
'M+': date.getMonth() + 1, // 月
'd+': date.getDate(), // 日
'H+': date.getHours(), // 時(shí)
'm+': date.getMinutes(), // 分
's+': date.getSeconds(), // 秒
'q+': Math.floor((date.getMonth() + 3) / 3), // 刻鐘
'S': date.getMilliseconds() // 毫秒
};
if (/(y+)/.test(format)) {
format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
}
for (var i in dset) {
if (new RegExp('(' + i + ')').test(format)) {
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? dset[i] : ('00' + dset[i]).substr(('' + dset[i]).length));
}
}
return format;
}
//方法調(diào)用
var timeString = cstDateFormat('Thu Jan 13 09:42:25 CST 2022', 'yyyy-MM-dd HH:mm:ss');
- 美好的一天绩鸣,不應(yīng)該被破壞,加油????