我有一个 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/