React Native DatePicker Specific Hours

1.7k Views Asked by At

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?

1

There are 1 best solutions below

0
On

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',
          }
        }