Code example for GregorianCalendar

Methods: get, setTime

0
        this.context = context;
    } 
 
    public void pickDate(String title, Optional<Date> optionalDate, final DatePickListener listener) {
        Date date = optionalDate.or(new Date());
        GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        // Set an EditText view to get user input 
        final DatePicker input = new DatePicker(context);
        input.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), null);
        int currentapiVersion = android.os.Build.VERSION.SDK_INT;
//        if (currentapiVersion >= 11) { 
//            try { 
//                Method m = input.getClass().getMethod("setCalendarViewShown", boolean.class); 
//                m.invoke(input, true); 
//            } catch (Exception e) { 
//            } // eat exception in our case 
//        } 
        new AlertDialog.Builder(context)
                .setTitle(title)
                .setView(input)