获取相对于北京的绝对日期, 时间不会因为更改电脑时区而变化

阅读更多
var getAbsDate = function (time) {
    var currentDate = new Date(time);
    var tmpHours = currentDate.getHours();
    var time_zone = -currentDate.getTimezoneOffset() / 60;
    if (time_zone < 0) {
        time_zone = Math.abs(time_zone) + 8;
        currentDate.setHours(tmpHours + time_zone);
    } else {
        time_zone -= 8;
        currentDate.setHours(tmpHours - time_zone);
    }
    return currentDate;
}


例子: getAbsDate("2018-07-12");

你可能感兴趣的:(JavaScript)