Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

javascript - 在JavaScript中获取客户端的时区偏移量(Getting the client's timezone offset in JavaScript)

How can I gather the visitor's time zone information?

(如何收集访问者的时区信息?)

I need the Timezone, as well as the GMT offset hours.

(我需要时区以及GMT偏移时间。)

  ask by árvízt?r? tük?rfúrógép translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

The time-zone offset is the difference, in minutes, between UTC and local time.

(时区偏移量是UTC与本地时间之间的差(以分钟为单位)。)

Note that this means that the offset is positive if the local timezone is behind UTC and negative if it is ahead.

(请注意,这意味着如果本地时区在UTC之后,则偏移量为正;如果在本地时区之前,则偏移量为负。)

For example, if your time zone is UTC+10 (Australian Eastern Standard Time), -600 will be returned.

(例如,如果您的时区是UTC + 10(澳大利亚东部标准时间),则将返回-600。)

Daylight savings time prevents this value from being a constant even for a given locale

(夏时制即使在给定的语言环境下也可以防止该值保持恒定)

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).

(请注意,并非所有时区都被整个小时抵消:例如,纽芬兰是UTC减去3h 30m(将夏令时排除在外)。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...