var d = new Date();
var local = d.getTime();
var offset = d.getTimezoneOffset() * 60000;
var localUtc = new Date().getTimezoneOffset() / 60;
var utcTime;
if (localUtc > 0) {
utcTime = local - offset;
} else {
utcTime = local + offset;
}
console.log("localUtc: " + localUtc);
var localTime = utcTime + 3600000 * Math.abs(localUtc);
console.log("localTime: " + localTime);
var nd = new Date(localTime);
var YY = nd.getFullYear() + "年";
var MM = nd.getMonth() + 1 + "月";
var dd = nd.getDate() + "日";
var hh = nd.getHours() + ":";
var mm = nd.getMinutes() + ":";
var ss = nd.getSeconds();
console.log(YY + MM + dd + hh + mm + ss);
// 将传入的时间转换为new Date时间格式
const toDate = new Date("2020-09-10 06:26:59");
console.log(toDate.getHours());
var d = toDate;
var localTime = d.getTime();
var localOffset = d.getTimezoneOffset() * 60000; //getTimezoneOffset()返回是以分钟为单位,需要转化成msvar utc = localTime + localOffset;
var offset = 9; //以韩国时间为例,东9区var korean = utc + 3600000 * offset;
var nd = new Date(korean);
console.log("Korean time is " + nd.toLocaleString()); // Korean time is 2020/9/10 上午7:26:59