Jquery Datetimepicker禁用日期
Jquery Datetimepicker disable dates
我使用jquery日期时间选择器来使用获取日期和时间
$(document).ready(function() {
$('#pickup_date').datetimepicker({
controlType: 'select',
timeFormat: 'hh:mm tt'
});
但我只需要启用从当前日期起的3周。如何解决这个问题。提前等待
<script>
function DisableWeekDays(date) {
var weekenddate = $.datepicker.noWeekends(date);
// In order to disable weekdays, we will invert the value returned by noWeekends functions.
// noWeekends return an array with the first element being true/false.. So we will invert the first element
var disableweek = [!weekenddate[0]];
return disableweek;
}
$(function() {
$( "#datepicker" ).datetimepicker({
beforeShowDay: DisableWeekDays
});
});
</script>
$('yourSelectorForDateTimePicker').datetimepicker({
formatDate:'Y/m/d',
minDate:0, //Today You can also '+1970/01/21' or '-1970/01/21' both ended up meaning -0 or +0
maxDate:'+1970/01/21' //3*7 days from today.
});
使用minDate
和maxDate
0
表示作为Unix时间的开始时间的1970/01/01
。您可以加上/减去字符串日期来设置可选择日期的范围。
案例你想把范围设置为昨天到明天,它将是
$('yourSelectorForDateTimePicker').datetimepicker({
formatDate:'Y/m/d',
minDate:'-1970/01/02', //Yesterday(plus one day from the 0 '1970/01/01')
maxDate:'+1970/01/02' //Tomorrow(minus one day from the 0 '1970/01/01')
});
http://xdsoft.net/jqplugins/datetimepicker/
上面的答案很好,但如果您想动态设置日期(基于当前日期)。
$(function () {
var currentDate = new Date();
var date = currentDate.toDateString();
$("#datetimepicker1").val(new Date() + " 00:01:00");
$('#datetimepicker1').datetimepicker({
format: 'DD/MM/YYYY',
minDate: date
});
});
- 将当前日期获取到变量中
- 将日期转换为字符串
- 将字符串传递给minDate
或
$(function () {
$("#datetimepicker1").val(new Date() + " 00:01:00");
$('#datetimepicker1').datetimepicker({
format: 'DD/MM/YYYY',
minDate: moment()
});
});
使用JSMoment和传递力矩。
相关文章:
- 比较从函数和生成的日期对象
- Json数据包含日期和时间格式
- Javascript日期格式类似于ISO,但本地
- 如何在输入字段中的按钮的帮助下打开日历,该字段的类型为“=”;日期”;
- 如何在JavaScript中延长当前日期
- 两位数的月份日期验证
- 更改angularjs中的日期-时间格式
- 将日期时间作为 JSON 发送将无法在我的视图中正确显示
- 将日期时间从json转换为可读格式
- NodeJS日期格式不起作用
- jquerydatetimepicker日期和时间应在框默认值中,而无需单击框
- 使用当前日期生成随机id
- primefaces日历可以禁用过去的日期和时间吗
- 提前阅读日期
- 在JavaScript中拆分日期字符串的更好方法是什么
- 查找最短和最长日期
- 将日期和时间转换为UTC格式的日期-Javascript
- jquery日期选择器年份范围默认值
- jquery日期选择器失去了交互性
- Javascript格式UTC日期