1

After adding +1 day and converting to ISO format, it will not execute correctly on the entry date 2022-03-27.

Isn't it related to daylight saving time?
If I also added the time to the date (2022-03-07 05:00:00), then the date conversion was correct.
But it is better for me to enter only the date.

function fnDp( inDtateIsoFormat ){
  "use strict";
  var d1 = inDtateIsoFormat,
      dp = new Date(d1);
  console.group("Date Bug JS "+d1+" +1 day");
  console.log("dp:\n\t",dp,'\n\t',dp.toISOString().substring(0,10));
  dp.setDate(dp.getDate()+1);
  console.log("dp +1 day:\n\t",dp,'\n\t',dp.toISOString().substring(0,10));
  console.groupEnd();
}

fnDp('2022-03-25');
fnDp('2022-03-27');
fnDp('2022-03-29');

Image console log

MatoP
  • 11
  • 1
  • `.getDate()` and `.setDate()` are local date methods. See comments from [here](https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript#comment121339013_3674550) for more details. – Nick Parsons Mar 27 '22 at 10:55

0 Answers0