概述
const applyBeginHour = '02:10:01';
const applyEndHour = '22:10:10';
限制小时
const disBeginHouse = () => {
const hours = [];
if (applyEndHour) {
const timeArr = applyEndHour.split(':');
// eslint-disable-next-line no-plusplus
for (let i = 0; i < 24; i++) {
if (i >= timeArr[0]) {
hours.push(i);
}
}
}
return hours;
};
const disEndHouse = () => {
const hours = [];
if (applyBeginHour) {
const timeArr = applyBeginHour.split(':');
// eslint-disable-next-line no-plusplus
for (let i = 0; i <= Number(timeArr[0]); i++) {
hours.push(i);
}
}
return hours;
};
<TimePicker disabledHours={disBeginHouse} />
上面限制小时已自测可以。下面是限制时、分、秒的具体方法:
const startTime = '00:00:00',
const endTime = '23:59:59'
// 现在时间以后的禁用
getDisabledHours=()=> {
let HOURS = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
var myDate = new Date();
// myDate.getHours(); //获取当前小时数(0-23)
// myDate.getMinutes(); //获取当前分钟数(0-59)
let hours = []
let HOURSDate=[];
// let time = this.startTime
let timeArr = [myDate.getHours(),myDate.getMinutes()]
// let timeArr = time.split(':')
for (var i = 0; i < parseInt(timeArr[0]); i++) {
console.log('hoursiiiiiiiiii', HOURS, i, HOURS.indexOf(i));
hours.push(i)
}
for ( var i = 0; i < HOURS.length; i++) {
if (hours.indexOf(i) < 0) {
HOURSDate.push(i)
}
}
return HOURSDate
}
getDisabledMinutes=(selectedHour)=> {
var MINITES = []
for(var i = 0;i<60;i++){
MINITES.push(i)
}
var myDate = new Date();
// myDate.getHours(); //获取当前小时数(0-23)
// myDate.getMinutes(); //获取当前分钟数(0-59)
let timeArr = [myDate.getHours(), myDate.getMinutes()]
let minutes = []
let MINITESDATE=[]
if (selectedHour == parseInt(timeArr[0])) {
for (var i = 0; i < parseInt(timeArr[1]); i++) {
minutes.push(i)
}
}
for(var i = 0;i<MINITES.length;i++){
if (minutes.indexOf(i) < 0) {
MINITESDATE.push(i)
}
}
return MINITESDATE
}
// 现在时间以前的限制
getDisabledHours () {
let hours = []
let time = this.startTime
let timeArr = time.split(':')
for (var i = 0; i < parseInt(timeArr[0]); i++) {
hours.push(i)
}
return hours
},
getDisabledMinutes (selectedHour) {
let time = this.startTime
let timeArr = time.split(':')
let minutes = []
if (selectedHour == parseInt(timeArr[0])) {
for(var i = 0; i < parseInt(timeArr[1]); i++) {
minutes.push(i)
}
}
return minutes
},
getDisabledSeconds (selectedHour, selectedMinute) {
let time = this.startTime
let timeArr = time.split(':')
let second = []
if (selectedHour == parseInt(timeArr[0]) && selectedMinute == parseInt(timeArr[1])) {
for(var i = 0; i <= parseInt(timeArr[2]); i++) {
second.push(i)
}
}
return second
}
最后
以上就是有魅力鞋垫为你收集整理的antd react TimePicker 时、分、秒限制的全部内容,希望文章能够帮你解决antd react TimePicker 时、分、秒限制所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复