I have time which is dynamic in 12 hour format.
Now i want to add 1 hour to the time.
I am adding 1 hour like
s_time = parseFloat(s_time) + 1;
But i dont think it is proper way to do it.
So can you guys suggest me how to do it.
Thanks
I have time which is dynamic in 12 hour format.
Now i want to add 1 hour to the time.
I am adding 1 hour like
s_time = parseFloat(s_time) + 1;
But i dont think it is proper way to do it.
So can you guys suggest me how to do it.
Thanks
var oldDate = new Date();
var hour = oldDate.getHours();
var newDate = oldDate.setHours(hour + 1);
console.log(newDate);
If you are having a date object, define a function like this and call wherever you want.
var addHours= function(dateObj, numHours){
var copiedDate = new Date(dateObj.getTime()); //cloning the date object.
copiedDate.setHours(copiedDate .getHours()+numHours);
return copiedDate;
}
Since the setDate() function will change the current object, we are cloning it.