Reputation: 13367
I have this date that is saved in my database as UTC and looks 2019-04-25T08:47:14.813
when I console log it out.
I read to convert that to my local time I can just cast it as a Date
and the do toString()
and it would be my local time zone, but it doesn't seem to work with UK Daytime saving.
For example, if I take the string above and do this:
let d = new Date(item.lastChecked);
console.log(d.toString());
console.log(item.lastChecked);
The response I get is:
Thu Apr 25 2019 08:47:14 GMT+0100 (British Summer Time)
2019-04-25T08:47:14.813
I don't want it to save (British Summer Time). I want it to say 9:47
instead.
How can I do that?
Upvotes: 3
Views: 250
Reputation: 92367
Add 'Z'
(which indicates that date is in UTC) to your input string
let d=new Date('2019-04-25T08:47:14.813'+'Z');
console.log(d.toString());
Upvotes: 3