Reputation: 704
I have a method which sets the created property of my token, like so:
const token = new Token();
console.log(moment().toDate());
token.created = moment().toDate().toJSON();
There's something I just can't get my head around and it's really confusing me.
The line console.log(moment().toDate());
prints Tue Sep 01 2020 14:11:39 GMT+0100
but when I check the property created
on debugger although it's using the same moment object and methods (except from calling toJSON()
) it produces a date time which is an hour behind like so: 2020-09-01T13:11:39.179Z
I store the moment date as a string in the created property because this will be stored in localStorage.
Does anyone know the reason for this?
Upvotes: 0
Views: 1515
Reputation: 943510
The times are the same. Look closely.
One marks the time zone as Z, the other as GMT+1.
Those time zones are 1 hour apart.
You can specify the time zone
Upvotes: 3