jquery - Javascript : time addition -


i have begin date :

var begindate = "29/04/2015"; var beginhour = "13:32"; 

i have duration variables :

var hourduration = "2"; var minuteduration = "10"; 

i have calculate end date :

i example, attempt :

var enddate = "29/04/2015"; var endhour = "15:42"; 

but if user set long hour time duration, enddate must take account end day.

is there way in javascript calculate times ?

without libraries this:

var begindate = "29/04/2015";  var beginhour = "13:32";    var hourduration = "2";  var minuteduration = "10";    var date = begindate.split('/'), time = beginhour.split(':');  date = new date(date[2], date[1] - 1, date[0], time[0], time[1]);  var newdate = new date(+date + (hourduration * 60 + +minuteduration) * 60000);    var enddate = newdate.getdate() + '/' + (newdate.getmonth() + 1) + '/' + newdate.getfullyear();  var endhour = newdate.gethours() + ':' + newdate.getminutes();    alert( enddate + ' ' + endhour);

but recommend use momentjs


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -