date.getTimezoneOffset

date.getTimezoneOffset

getTimezoneOffset()方法以UTC为单位从UTC返回当前区域设置(主机系统设置)。

语法

dateObj.getTimezoneOffset()

返回值

表示与UTC的时区偏移的数字,以分钟为单位,表示基于当前主机系统设置的日期。

描述

时区偏移量是UTC和本地时间之间的差值,以分钟为单位。请注意,这意味着如果本地时区在UTC之后,则偏移量为正; 如果在前,则偏移量为负值。例如,对于UTC + 10:00(澳大利亚东部标准时间,符拉迪沃斯托克时间,查莫罗标准时间)时区,将返回-600。

Current LocaleUTC-8UTCUTC+3
Return Value4800-180

返回的时区偏移量是适用于调用它的日期的偏移量。如果主机系统配置为夏令时,则偏移量将根据日期代表的日期和时间以及夏令时适用的情况发生变化。

例子

Using getTimezoneOffset()

// Get current timezone offset for host device var x = new Date( var currentTimeZoneOffsetInHours = x.getTimezoneOffset() / 60; 1 // Get timezone offset for International Labour Day (May 1) in 2016 // Be careful, the Date() constructor uses 0-indexed month so May is // represented with 4 (and not 5) var labourDay = new Date(2016, 4, 1) var labourDayOffset = labourDay.getTimezoneOffset() / 60;

规格

SpecificationStatusComment
ECMAScript 1st Edition (ECMA-262)StandardInitial definition. Implemented in JavaScript 1.0.
ECMAScript 5.1 (ECMA-262)The definition of 'Date.prototype.getTimezoneOffset' in that specification.Standard
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Date.prototype.getTimezoneOffset' in that specification.Standard
ECMAScript Latest Draft (ECMA-262)The definition of 'Date.prototype.getTimezoneOffset' in that specification.Living Standard

浏览器兼容性

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic Support(Yes)(Yes)(Yes)5(Yes)(Yes)

FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support(Yes)(Yes)(Yes)(Yes)(Yes)(Yes)(Yes)