Reputation: 389
I'm using this datetime picker and want to set the minDate to today at 8 am.
The timepicker has the attribute minDate
that can take input like new Date(2012, 05, 15, 8, 00)
. I would like it be able to do something like new Date(getFullYear(), getMonth(), getDate(), 8, 00)
, but that doesn't seem to work.
Is there any way to do that?
Upvotes: 1
Views: 253
Reputation: 195972
Well... if you have to do all the calculations when you pass it as a param try
(function(){var d = new Date();d.setHours(8);d.setMinutes(0);d.setSeconds(0);return d;})()
Upvotes: 1
Reputation: 21713
You need to get today's date first using
var today = new Date();
Then call those methods on today
.
new Date(today.getFullYear(), today.getMonth(), today.getDay(), 8, 00)
Upvotes: 3
Reputation: 74036
You can create a Date
object (MDN) with the current date/time and then adjust it to your needs like the following, before passing it on to the datetime picker.
var minToday = new Date();
minToday.setHours( 8 );
minToday.setMinutes( 0 );
Note that this uses the local time of the user, which may be different from your server time!
Upvotes: 5