0

I'm incrementing one day (24*60*60) to a particular date in javascript until it is greater than today' date in order to achieve a process runs every 24 hours. but because of the EST/EDT shift, the schedule reduces by 1 hour. how to fix this..?

var now = new Date();
var next = some past date ;
var incr = 24 * 60 * 60 * 1000 ;

while (next < now) {
next = new Date (next.valueOf() + incr);
}
return next ;

say for example, i keep past date as '01-Sep-2015 00:00:00'. when the date moves to Nov 2nd 2015, due to 1 hour time shift on 1st Nov 2015, the next value sets as '01-Nov-2015 23:00:00' . The reason why it was incremented with value is because the requirement wants it to be flexible to increase by any number of hours. Say, the process may need to run every 6 hours, then we will change the increment to 6 * 60 * 60 * 1000

please help.

  • You don't have t keep creating new dates, you can increment the date by simply adding one to the date: `next.setDate(next.getDate() + 1)`. – RobG Jun 21 '16 at 00:13
  • The reason why it was incremented with value is because the requirement wants it to be flexible to increase by any number of hours. Say, the process may need to run every 6 hours, then we will change the increment to 6 * 60 * 60 * 1000 – Senthil Kumar C Jun 22 '16 at 00:35
  • Yes of course, the point is that you can change a Date's time value (and hence the moment in time that it represents) without creating a new Date object. In the context of your answer it would be `next.setTime(next.getTime() + incr)`. – RobG Jul 01 '16 at 01:20

0 Answers0