简体   繁体   中英

How do I restrict dates on datepicker after a certain time?

At the moment I have this code here:

<script type="text/javascript" src="catalog/view/javascript/jquery/ui/jquery-ui-timepicker-addon.js"></script> 
<script type="text/javascript"><!--
if ($.browser.msie && $.browser.version == 6) {
    $('.date, .datetime, .time').bgIframe();
}

$('.date').datepicker({dateFormat: 'D M dd, yy', minDate:2, beforeShowDay: $.datepicker.noWeekends});
$('.datetime').datetimepicker({
    dateFormat: 'yy-mm-dd',
    timeFormat: 'h:m'
});
$('.time').timepicker({timeFormat: 'h:m'});
//--></script> 

It works great by I have one thing I would like to add to it.

I use the datepicker so my customers can choose a date when they can pick up an item.

I would like it to blank out the the next two days after it reaches 5.30pm EST.

So at 1pm on Monday I can only select Wednesday onwards. If it is 6pm Monday I can only order Thursday onwards.

Does anyone know how to do this? I couldn't quite figure it out from the API website.

Many Thanks

Peter

per the docs: http://jqueryui.com/datepicker/#min-max

you can set minDate: 2 depending on what time it is now.

var min = 1;
var currentTime = new Date();
if (currentTime.getHours() >=17 && currentTime.getMinutes() >=30){
    min = 2;
}

then pass min into minDate .

as ahren pointed out, though, this will be the user's time, not yours. If you want to find the timezone and adjust from there you can use getTimeZoneOffset http://www.w3schools.com/jsref/jsref_gettimezoneoffset.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM