Is there a way in React native to choose specific hours in the date picker ?
for example here in the DatePickerIOSe, we can choose mode: time
. and there are two other Props (maximumDate, minimumDate) , is there a way to specify those to just hours and minutes for example
maximumDate = new Date('12:00:00')
or something like that?
Asked
Active
Viewed 1,447 times
2

Ahmad Yousef
- 621
- 9
- 20
-
2You can below code, hope Its work; https://snack.expo.io/@erdemildiz/4e9a4d?session_id=snack-session-ZDoH8nrTn – eildiz Nov 18 '19 at 11:34
-
That solved it, I'm writing an answer with the complete code so anyone can use it. – Ahmad Yousef Nov 18 '19 at 19:11
1 Answers
0
Like @erdemildiz said, we can solve this easily by setHours()
and setMinutes()
Here is a code using Tcomb to make a timer from 10:00:00 to 22:00:00
var startTime = new Date()
startTime.setHours(10)
startTime.setMinutes(0)
var finishTime = new Date()
finishTime.setHours(22)
finishTime.setMinutes(0)
timer: {
label: 'select time',
maximumDate: finishTime,
minimumDate: startTime,
minuteInterval: 10,
mode: 'time',
config: {
format: (date) => { return moment(date).format('HH:mm A') },
defaultValueText: 'Choose time',
}
}

Ahmad Yousef
- 621
- 9
- 20