JS判断当前地区是否有夏令时, //判断是否有夏令时, 如果年初和年中的时区不一样的话就有夏令时
Date.prototype.canDST = function () {
var e = new Date(this.getFullYear(), 0, 1),
t = new Date(this.getFullYear(), 6, 1);
return e.getTimezoneOffset() != t.getTimezoneOffset()
}
(new Date()).canDST() // ture of false
var e = new Date(this.getFullYear(), 0, 1),
t = new Date(this.getFullYear(), 6, 1);
return e.getTimezoneOffset() != t.getTimezoneOffset()
}
(new Date()).canDST() // ture of false
JS 判断当前是否在夏令时区
//JS 检测当前时间是否为夏令时,返回较大的时区
Date.prototype.stdTimezoneOffset = function () {
var e = new Date(this.getFullYear(), 0, 1),
t = new Date(this.getFullYear(), 6, 1);
return Math.max(e.getTimezoneOffset(), t.getTimezoneOffset())
},
//判断是否在夏令时.如果目前的时区小于夏令时区
Date.prototype.dst = function () {
return this.getTimezoneOffset() < this.stdTimezoneOffset()
}
(new Date()).dst() // ture of false
Date.prototype.stdTimezoneOffset = function () {
var e = new Date(this.getFullYear(), 0, 1),
t = new Date(this.getFullYear(), 6, 1);
return Math.max(e.getTimezoneOffset(), t.getTimezoneOffset())
},
//判断是否在夏令时.如果目前的时区小于夏令时区
Date.prototype.dst = function () {
return this.getTimezoneOffset() < this.stdTimezoneOffset()
}
(new Date()).dst() // ture of false