I want to add one hour in 24 hours time format using Javascript or JQuery.
like
if 23:00 then it should be 00:00
if 11:00 then 12:00
if 13:00 then 14:00
if 09:00 then 10:00
for that I tried below code. That's perfectly works
function increase24TimeByOne(timeStr) {
var splitedTimeStr = timeStr.split(':');
var hours = parseInt(splitedTimeStr[0]);
var minutes = splitedTimeStr[1].substring(0, 2);
var nextHours = (hours + 1);
if(nextHours.toString().length == 1){
nextHours = "0" + nextHours;
}
if(nextHours == 24){
nextHours = "00"
}
return nextHours + ":" + minutes;
}
but I want to know that code is better or not ?
Can anyone please suggest ?
Thanks in advance