0

I am struggling to come up with a fix where when I input a date, say 2021-11-08T02:43:34.608Z in ISO format, this inputs the next day, November 8, while the current date in my timezone is November 7.

I've tried using this line of code I found from stack overflow, but it does not make a difference:

const [date, setDate] = useState(new Date())

<DayPickerInput
  format="YYYY/MM/DD"
  onDayChange={(day) => {
    setDate(new Date(day.getTime() - day.getTimezoneOffset() * 60000))
  }}
/>

Basically, anytime in the evening, the ISO date displays the next day. This is obviously not what I am looking for.

Here is a helpful ISO converter I found to help make sense of this bug

Notice Check out this screenshot. While the current local time in November 7, 7:43pm, the ISO time is the following day.

Image

Tyler Morales
  • 1,440
  • 2
  • 19
  • 56
  • basically like this https://stackoverflow.com/q/6525538/10197418 ? – FObersteiner Nov 09 '21 at 08:22
  • 1
    Which tool and programming language are you using? Please tag your question accordingly. – Ole V.V. Nov 09 '21 at 08:50
  • 1
    The `Z` at the end of your input string means that the date and time are in terms of UTC. If you intended them to be in terms of your local time, omit the `Z`. Also, the technique illustrated in your example is called "epoch shifting" and it is usually the wrong thing to do. – Matt Johnson-Pint Nov 09 '21 at 15:36

0 Answers0