在JavaScript中获取客户端的时区偏移量 [英] Getting the client's timezone offset in JavaScript

查看:122
本文介绍了在JavaScript中获取客户端的时区偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何收集访客的时区信息?我需要Timezone,以及GMT抵消时间。

How can I gather the visitor's time zone information? I need the Timezone, as well as the GMT offset hours.

推荐答案

var offset = new Date().getTimezoneOffset();
console.log(offset);


时区偏移是UTC与本地时间之间的差异(以分钟为单位)。请注意,这意味着如果本地时区落后于UTC,则偏移量为正,如果前置,则偏移量为负。例如,如果您的时区是UTC + 10(澳大利亚东部标准时间),则将返回-600。夏令时会阻止此值即使对于给定的区域设置也是常量

The time-zone offset is the difference, in minutes, between UTC and local time. Note that this means that the offset is positive if the local timezone is behind UTC and negative if it is ahead. For example, if your time zone is UTC+10 (Australian Eastern Standard Time), -600 will be returned. Daylight savings time prevents this value from being a constant even for a given locale




  • Mozilla日期对象参考

    • Mozilla Date Object reference
    • 请注意,并非所有时区都按整个小时偏移:例如,纽芬兰是UTC减去3小时30分钟(将夏令时除以等式)。

      Note that not all timezones are offset by whole hours: for example, Newfoundland is UTC minus 3h 30m (leaving Daylight Saving Time out of the equation).

      这篇关于在JavaScript中获取客户端的时区偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆