Materialdatepicker returning wrong value android studio

Asked

Viewed 24 times

0

I’m using Materialdatepicker in android studio so the user can choose the date of birth, after selecting the date, the value returned is a long with the timestamp of the selected date (milliseconds since 01/01/1970). The problem is that the result obtained is slightly wrong, example: If the user selects the date 05/10/1998, the date returned is one day before this, ie the calendar returns 04/10/1998.

My code:

    Calendar calendar = Calendar.getInstance();
    MaterialDatePicker.Builder<Long> builder = 
    MaterialDatePicker.Builder.datePicker();

    MaterialDatePicker<Long> picker = builder.build();

    picker.show(getChildFragmentManager(), picker.toString());

    picker.addOnPositiveButtonClickListener(new MaterialPickerOnPositiveButtonClickListener<Long>() {
        @Override
        public void onPositiveButtonClick(Long selection) {

            calendar.setTimeInMillis(selection);


        }
    });

The instance of calendar, now with timeInMillis has the date selectioanda, only with a day before. How can I fix this?

  • What version of the material are you using? I tested your code with version 1.3.0-alpha02 and displayed the correct date. Can put as you are formatting the date to be displayed?

No answers

Browser other questions tagged

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