本文介绍了如何在jquery datetimepicker中禁用与当前日期时间相关的过去日期时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用jquery datetimepicker。



我不想允许用户选择当前或未来日期以外的任何过去日期。

我已达到上述功能。所有,我面临的问题是随着时间的推移。



我不想让用户选择除当前或未来时间之外的任何过去时间,即如果当前时间是下午1:00,则用户无法选择过去时间到下午1:00





我怎样才能实现这个目标?



我的尝试:



function getCurrentTime(date){

var hours = date.getHours(),

minutes = date.getMinutes(),

ampm = hours > = 12? 'pm':'am';



小时=小时%12;

小时=小时?小时:12; //小时'0'应为'12'

分钟=分钟< 10? '0'+分钟:分钟;



返回小时+':'+分钟+''+ ampm;

}



var time = new Date()。getTime();

var currentdate = new Date(time);

var datetime = currentdate.getDate()+/

+(currentdate.getMonth()+ 1)+/

+ currentdate.getFullYear()+

+ currentdate.getHours()+:

+ currentdate.getMinutes();

// var time = currentdate.getHours()+:+ currentdate.getMinutes();





$(#myDate )。datetimepicker({

dayOfWeekStart:1,

minDate:0,

minTime:getCurrentTime(new Date()),

setDate:currentdate,

格式:'d / m / YH:我',

格式时间:'H:我',

formatDate:'d / m / Y',

ampm:true,

step:workingHrSlot

// onChangeDateTime:logic,

// onShow:logic

});



I'm using jquery datetimepicker.

I don't want to allow user to select any past date other than current or future date.
I have achieved above functionality. All, i'm facing problem is with time.

I don't want to allow user to select any past time other than current or future time, i.e. if current time is 1:00 pm, user can't select past time to 1:00 pm


How can I achieve this?

What I have tried:

function getCurrentTime(date) {
var hours = date.getHours(),
minutes = date.getMinutes(),
ampm = hours >= 12 ? 'pm' : 'am';

hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;

return hours + ':' + minutes + ' ' + ampm;
}

var time = new Date().getTime();
var currentdate = new Date(time);
var datetime = currentdate.getDate() + "/"
+ (currentdate.getMonth()+1) + "/"
+ currentdate.getFullYear() + " "
+ currentdate.getHours() + ":"
+ currentdate.getMinutes() ;
//var time = currentdate.getHours() + ":" + currentdate.getMinutes();


$("#myDate").datetimepicker({
dayOfWeekStart: 1,
minDate: 0,
minTime: getCurrentTime(new Date()),
setDate:currentdate,
format: 'd/m/Y H:i',
formatTime: 'H:i',
formatDate: 'd/m/Y',
ampm: true,
step: workingHrSlot
//onChangeDateTime: logic,
//onShow: logic
});

推荐答案


这篇关于如何在jquery datetimepicker中禁用与当前日期时间相关的过去日期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 03:54