I have the following string returned by my web service: '10:00:00'.
It is successfully being disabled in my timepicker via:
$('#appointmentTimeTextbox').timepicker('option',
'disableTimeRanges',
[[obj.appointmentTime, obj.appointmentEndTime]]);
What I would like is to add 30 minutes (one option in the timepicker) to obj.appointmentEndTime
. I have tried:
var appointmentEndTime = new date(obj.appointmentEndTime);
appointmentEndTime.setHours(appointmentEndTime.getHours() + .5);
to no avail.
You've got a few issues going on here:
1) This may just be a typo in the question, but the date constructor must be capitalized:
new Date(...
2) The
setHours()
method only takes integer values for the "hours" parameter . . . from MDN:You can add in a half an hour two ways: by providing a "minutes" parameter in the
setHours()
call:. . . or by simply using the
setMinutes()
method:3) When you create the new date value with:
. . . you are working with a brand new
Date
object, so you will either need to copy the new time value back into the originalobj.appointmentEndTime
property, or you will need to create the value from the newappointmentEndTime
variable, and pass that into thetimepicker()
method instead ofobj.appointmentEndTime
.UPDATE
Okay, so I looked at your Fiddle and the issue that you are having now is that you can't create a date with simply a time value:
Again, looking to MDN (a great resource, by the way), the valid inputs for the
Date
constructor are:So your best option would be to pick a date (the current date would be easiest), and then override the time values on that date, to get the value that you want:
Using that (and your value of '10:00:00
), the time value of the date should be
10:30:00(which you can create using the
getHours(),
getMinutes(), and
getSecondsmethods on
appoinementEndTime`).