public void setDate ( String date ) { if ( date == null || date . trim ( ) . isEmpty ( ) ) { throw new IllegalArgumentException ( "Date cannot be null or empty." ) ; } try { Date dateToSet = new SimpleDateFormat ( "MM/dd/yyyy" ) . parse ( date ) ; Calendar to = Calendar . getInstance ( ) ; to . setTime ( dateToSet ) ; setDate ( to ) ; } catch ( ParseException e ) { throw new IllegalArgumentException ( e ) ; } }
This function set the date on the DatePicker using the input paramter in the format of MM . dd . yyyy string