Date.prototype.getTimezoneOffset() - JavaScript 编辑

The getTimezoneOffset() method returns the time zone difference, in minutes, from current locale (host system settings) to UTC.

Syntax

dateObj.getTimezoneOffset()

Return value

A number representing the time-zone offset, in minutes, from the date based on current host system settings to UTC.

Description

The time-zone offset is the difference, in minutes, from local time to UTC.

Note that this means that the offset is positive if the local timezone is behind UTC, and negative if it is ahead. For example, for time zone UTC+10:00 (Australian Eastern Standard Time, Vladivostok Time, Chamorro Standard Time), -600 will be returned.

Current LocaleUTC-8UTCUTC+3
Return Value4800-180

The time zone offset returned is the one that applies for the Date that it's called on.

If the host system is configured for daylight saving, the offset will change depending on the date and time that the Date represents and that daylight saving applies.

Examples

Using getTimezoneOffset()

// Get current timezone offset for host device
let x = new Date();
let currentTimeZoneOffsetInHours = x.getTimezoneOffset() / 60;
// 1

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

Specifications

Specification
ECMAScript (ECMA-262)
The definition of 'Date.prototype.getTimezoneOffset' in that specification.

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:103 次

字数:3984

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文