0

I have my date stored in database as 2023-06-15 23:59:59.0000000, UK date/time.

When in JavaScript I set as a date, new Date('2023-06-15T23:59:59Z'), it returns the day after, "Fri Jun 16 2023 00:59:59 GMT+0100 (British Summer Time)" .

I can't get my head around what I need to do, when I'm storing the date do I need to take an hour off or is there a different method in JavaScript I need to call to get the date I'm expecting which would be "Thu Jun 15 2023 23:59:59 GMT+0100 (British Summer Time)"?

Whit Waldo
  • 4,806
  • 4
  • 48
  • 70
  • Are you in the UTC time zone? If not, then it changes the date because of different time zones. – Geshode Jun 16 '23 at 08:21
  • When you use `Z` in the end, it means `UTC+0`. – Harun Yilmaz Jun 16 '23 at 08:22
  • 2
    It isn't a day later. The value you are inputting is (explicitly) in the UTC time zone. The value you are displaying is in your local time zone, which is BST (UTC+1). It looks like a day later because the +1 pops from a minute before midnight to a minute before 1am. – Quentin Jun 16 '23 at 08:22
  • Use [Intl.DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat) if you want to render a UTC date. – Quentin Jun 16 '23 at 08:25

0 Answers0