Minimum date on Ionic Native Datepicker

Asked

Viewed 66 times

0

I am using the Datepicker plugin to receive a date, I can get the date normally, the problem occurs when I use the property minDate, in my understanding, this would be a minimum date for selection, but when I set a date in the property, nothing happens, there is some specific date format for Android?

getDateFinal() {
    this.datePicker.show({
      date: new Date(),
      mode: 'date',
      minDate: new Date(),
      androidTheme: this.datePicker.ANDROID_THEMES.THEME_HOLO_DARK
    }).then(
      date => this.dataFinal = this.sharedProvider.transformDate(date),
      err => console.log('Error occurred while getting date: ', err)
    );
  }

Documentation: https://ionicframework.com/docs/v3/native/date-picker/

1 answer

0


As the documentation on https://github.com/VitaliiBlagodir/cordova-plugin-datepicker#mindate--Ios-android-windows :

minDate is a Date Object for iOS and a millisecond Precision Unix timestamp for Android, so you need to Account for that when using the plugin. Also, on Android, only the date is enforced (time is not).

That is, to work on Android you need to pass the date on UNIX timestamp instead of a date object.

minDate: new Date().getTime() / 1000

  • So man, I got it solved here, really need to call the getTime() method on Android.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.