javascript - 为什么 'getTimezoneOffset' 在 Date.prototype 中实现而不是作为 Date 的静态方法?

标签 javascript date

为什么方法 getTimezoneOffset 被实现为 Date 原型(prototype)对象的方法而不是 Date 对象的静态方法,因为它总是返回当前主机系统的差异而不是 Date实例本身?

有什么可以理解的原因吗?

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset

(顺便说一句,我标记为“Java”是因为我听说 JavaScript 中的许多 Date 函数都受到 Java 的启发)

最佳答案

因为夏令时。 根据日期是在夏令时更改之前还是之后,UTC 偏移量在同一时区会有所不同。

在该 MDN 页面中进一步引用:

The time zone offset returned is the one that applies for the Date that it's called on. Where 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.

关于javascript - 为什么 'getTimezoneOffset' 在 Date.prototype 中实现而不是作为 Date 的静态方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50141269/

相关文章:

android - 如何在 android 中获取 WEEK_OF_YEAR 内的日期列表?

python - 我如何使用 Python(精确到分钟)计算过去 30 天的时间?

arrays - 我需要帮助根据字符串中的日期匹配对列进行动态排序

javascript - 排序数组元素(带数字的字符串),自然排序

javascript - 表格鼠标悬停

javascript - 为什么 2///2 在 Javascript 中是 2?

java - 无法在数据库中保存日期(月/日/年)

java - SimpleDateFormat 不工作

javascript - 有人能解释一下下面这段 JavaScript 代码吗?

javascript - AngularJS 通过源标签动态加载普通的旧 Javascript