Hướng dẫn javascript timezone offset - bù đắp múi giờ javascript

Phương pháp getTimezoneOffset() trả về sự khác biệt, tính theo phút, giữa một ngày được đánh giá trong múi giờ UTC và cùng ngày được đánh giá trong múi giờ địa phương.getTimezoneOffset() method returns the difference, in minutes, between a date as evaluated in the UTC time zone, and the same date as evaluated in the local time zone.

Nội phân chính

  • Giá trị trả về
  • Sự mô tả
  • Giá trị âm và giá trị tích cực
  • Kết quả khác nhau trong các vùng tiết kiệm ánh sáng ban ngày (DST)
  • Sử dụng getTimezononeOfset ()
  • getTimeZoneOfset () và DST
  • GetTimeZoneOfset () và dữ liệu lịch sử
  • Thông số kỹ thuật
  • Tính tương thích của trình duyệt web

Thử nó

Cú pháp

Giá trị trả về

Sự mô tả

Sự mô tả

Giá trị âm và giá trị tích cực

Giá trị âm và giá trị tích cực

Kết quả khác nhau trong các vùng tiết kiệm ánh sáng ban ngày (DST)

Kết quả khác nhau trong các vùng tiết kiệm ánh sáng ban ngày (DST)

Sử dụng getTimezononeOfset ()

getTimeZoneOfset () và DST getTimezoneOffset()'s behavior will never differ based on the time when the code is run — its behavior is always consistent when running in the same region. Only the value of date affects the result.

GetTimeZoneOfset () và dữ liệu lịch sử

Thông số kỹ thuật

Sử dụng getTimezononeOfset ()

// Create a Date instance for the current time
const currentLocalDate = new Date();
// Create a Date instance for 03:24 GMT-0200 on May 1st in 2016
const laborDay2016at0324GMTminus2 = new Date('2016-05-01T03:24:00Z-02:00');
currentLocalDate.getTimezoneOffset() === laborDay2016at0324GMTminus2.getTimezoneOffset();
// true, always, in any timezone that doesn't annually shift in and out of DST
// false, sometimes, in any timezone that annually shifts in and out of DST

getTimeZoneOfset () và DST

GetTimeZoneOfset () và dữ liệu lịch sử

const nyOffsetSummer = new Date('2022-02-01').getTimezoneOffset(); // 300
const nyOffsetWinter = new Date('2022-08-01').getTimezoneOffset(); // 240

GetTimeZoneOfset () và dữ liệu lịch sử

Thông số kỹ thuật

const shModernOffset = new Date('2022-01-27').getTimezoneOffset(); // -480
const shHistoricalOffset = new Date('1943-01-27').getTimezoneOffset(); // -540

Tính tương thích của trình duyệt web

Thông số kỹ thuật

Tính tương thích của trình duyệt web
Thử nó
# sec-date.prototype.gettimezoneoffset

Tính tương thích của trình duyệt web

Thử nó

Cú pháp