I am trying to subtract hours from a given date time string using javascript. My code is like:
var cbTime = new Date();
cbTime = selectedTime.s
The reason is that setHours()
, setMinutes()
, etc, take an Integer
as a parameter. From the docs:
...
The setMinutes()
method sets the minutes for a specified date according to local time....
Parameters:
An integer between 0 and 59, representing the minutes.
So, you could do this:
var selectedTime = new Date(),
cbTime = new Date();
cbTime.setHours(selectedTime.getHours() - 5);
cbTime.setMinutes(selectedTime.getMinutes() - 30);
document.write('cbTime: ' + cbTime);
document.write('
');
document.write('selectedTime: ' + selectedTime);