I have a C# application that return in JSON an expiration date of an authentication token like this:
"expirationDate":"Fri, 27 Mar 2015 09:12:45 GMT"
In my TypeScript I check that the date is still valid here:
isAuthenticationExpired = (expirationDate: string): boolean => {
var now = new Date().valueOf();
var exp: any = Date.parse(expirationDate).valueOf();
return exp - now <= 0;
};
What I would like to know is what time zone does new Date()
use when it is returning a date?
JavaScript will use the client's local time but it also has UTC / GMT methods. The following is from 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.
While methods are available to access date and time in both UTC and the localtime zone, the date and time are stored in the local time zone:
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.
Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date