jquery - How to find if we passed a day when adding minutes to datetime object in javascript -
i having date range june 21 jun 27.i want add 20 minutes start date every 5secs , make service call values. also, second service call need previous end datetime start datetime.for example service call 1, start date jun 21, 5:00 pm end date jun 27, 5:20 pm second service call should have start date jun 21, 5:20 pm end date jun 21 , 5:40 pm how can achieve through javascript , how change date once pass 24 hrs. thanks!
//my start date , end date var startdt = newdate(data.startdate); var enddt = newdate(data.enddate); var count = 0; setinterval(function() { if(count == 0){ var sdt= new date(startdt).toisostring(); var edt= new date(startdt.setminutes(startdt.getminutes() + 10)).toisostring(); } else{ var sdt = new date(startdt.setminutes(startdt.getminutes() + )).toisostring(); } //calling apy sdt , edt here; count++; },5000)
the javascript setminutes()
method automatically go next hour or day when minutes or hour wrap around.
starttime = new date(endtime); // copy old endtime starttime endtime.setminutes(endtime.getminutes() + 20); // add 20 minutes endtime
here's full code:
//my start date , end date var startdt = newdate(data.startdate); var enddt = newdate(data.enddate); var count = 0; var interval = setinterval(function() { if (new date() > enddt) { // reached enddt clearinterval(interval); return; } var sdt = new date(startdt).toisostring(); var edt = new date(startdt.setminutes(startdt.getminutes() + 20)).toisostring(); //calling apy sdt , edt here; count++; },5000)