3

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?

Community
  • 1
  • 1
r3plica
  • 13,017
  • 23
  • 128
  • 290
  • 1
    Possible duplicate of [How to check if the DST (Daylight Saving Time) is in effect and if it is what's the offset?](https://stackoverflow.com/questions/11887934/how-to-check-if-the-dst-daylight-saving-time-is-in-effect-and-if-it-is-whats) – Anurag Srivastava Apr 25 '19 at 08:55
  • Is your machine's local time set correctly? – Rafael Apr 25 '19 at 08:59

1 Answers1

3

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());
Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345