K
K
Kentavr162021-06-13 13:22:48
JavaScript
Kentavr16, 2021-06-13 13:22:48

Why is the wrong time displayed after using date.toISOString()?

I'm interested in this piece of code:

const handleClickDay = (value) =>{
    console.log(value)
    var valToStr = value.toISOString().slice(0,10)
    console.log(valToStr)

where value is the new Date() object. I receive date, I transform to isostring and I cut off seconds. but here are the miracles: in the console we get:

Wed Jun 02 2021 00:00:00 GMT + 0300 (Saudi Arabia, standard time)
2021-06-01

That is, the day from new Date is 1 more than after conversion. WHY?
Of course, I set up a crutch, add +1 day and everything works, but I would like to understand what's the matter.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question