3

My question is similar to this one, but I need to process ISO strings.

I've tried to adapt the solution from the other question:

var getNextDay = function(day) {
    var date = new Date(day);
    date.setDate(date.getDate() + 1);
    return date.toISOString().slice(0, 10);
};

This actually works in most cases, e.g. getNextDay('2014-03-31') returns '2014-04-01'.

However, getNextDay('2014-03-30') gives me '2014-03-30' (The full string before slicing is '2014-03-30T23:00:00.000Z')

Does anyone know why this happens and how to solve it?

Community
  • 1
  • 1
Marko Knöbl
  • 447
  • 2
  • 9
  • Try `setUTCDdate` and `getUTCDate` instead. It seems to be a daylight-saving-timing issue. – Bergi Sep 12 '16 at 14:46

1 Answers1

3

This is caused by Daylight saving adjustment that happened on that date. March 30, 2014: Europe starts Daylight Saving Time

Fix it by using UTCDate instead:

var getNextDay = function(day) {
    var date = new Date(day);
    date.setUTCDate(date.getUTCDate() + 1);
    return date.toISOString().slice(0, 10);
};
wvdz
  • 16,251
  • 4
  • 53
  • 90