javascript - JavaScript new Date() 使用什么时区?

标签 javascript date typescript

我有一个 C# 应用程序,它以 JSON 格式返回身份验证 token 的到期日期,如下所示:

"expirationDate":"Fri, 27 Mar 2015 09:12:45 GMT"

在我的 TypeScript 中,我检查这里的日期是否仍然有效:

isAuthenticationExpired = (expirationDate: string): boolean => {
    var now = new Date().valueOf();
    var exp: any = Date.parse(expirationDate).valueOf();
    return exp - now <= 0;
};

我想知道 new Date() 在返回日期时使用什么时区?

最佳答案

JavaScript 将使用客户端的本地时间,但它也有 UTC/GMT 方法。以下内容来自 Mozilla:

The JavaScript Date object supports a number of UTC (universal) methods, as well as local time methods. UTC, also known as Greenwich Mean Time (GMT), refers to the time as set by the World Time Standard. The local time is the time known to the computer where JavaScript is executed.

虽然可以使用 UTC 和本地时区访问日期和时间的方法,但日期和时间存储在本地时区中:

Note: It's important to keep in mind that the date and time is stored in the local time zone, and that the basic methods to fetch the date and time or its components all work in the local time zone as well.

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

关于javascript - JavaScript new Date() 使用什么时区?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29297257/

相关文章:

javascript - 向正则表达式添加动态值

Javascript - 如何返回数组中最大的四个数字?

java - 将字符串 "yyyy-MM-dd"转换为 "E, MMM d"

javascript - 禁用 Angular 组件

javascript - jQuery Mobile - 提交表单,重定向到页面 ID?

javascript - 使用 Javascript 数组和对象创建表

javascript - 日期格式 - momentjs - 使用语言环境分别提取日期和时间

java - 如何从 Java 语言环境的时区获取日期模式

javascript - 如何在 Angular2 中对 Http get MockBackend 进行单元测试?

javascript - 在 Objection.js 中以多对多方式插入额外字段