0

I am storing a date as a django DateField in my database. It simply looks like "2020-06-25" in the database.

This string is returned from my api, and passed into a javascript "Date" as such:

date = new Date(due_date)

logging this date results in:

Wed Jun 24 2020 17:00:00 GMT-0700 (Pacific Daylight Time)

I don't care about the time, only the date. How do I get javascript Date to ignore the time, and not adjust for the difference in timezone between the DB and the local user? If a user sets the due date for a project in one timezone, I want every person to see the same due date.

ambe5960
  • 1,870
  • 2
  • 19
  • 47
  • 1
    what does due_date looks like ? because `new Date(2020-06-25)` will result to this `2020-06-25T00:00:00.000Z` – Sven.hig Jun 11 '20 at 01:48
  • @Sven.hig Interesting... `new Date("2020-06-25")` gives me `Wed Jun 24 2020 17:00:00 GMT-0700 (Pacific Daylight Time)` – ambe5960 Jun 11 '20 at 02:00
  • 1
    Dates in YYYY-MM-DD format are parsed as UTC, a rather bad [decision by the TC39](https://github.com/tc39/ecma262/issues/87) some years ago. – RobG Jun 11 '20 at 03:21

1 Answers1

0

Converting a string to a date in JavaScript

This guided me to the answer. Browsers handle this differently, but you can force the date to display in UTC time, rather than letting the browser decide if it wants to covert to the end user's local time or not.

ambe5960
  • 1,870
  • 2
  • 19
  • 47
  • 1
    This isn't an answer, it might be a useful comment. If you think it's a duplicate, mark it as one. – RobG Jun 11 '20 at 03:29