I\'m calling a MaterialDatePicker like this in Android:
MaterialDatePicker.Builder> builder = MaterialDatePicker.Builder.dateRa
For those that struggle with this and the fact that their timestamp is off a day, here is my working solution. I have a requirement of API 23 so I could not use any of the nice Epoch functions in java.time.*. The key for me was realizing I need to do the timezone offset math.
picker.addOnPositiveButtonClickListener(new MaterialPickerOnPositiveButtonClickListener() {
@Override
public void onPositiveButtonClick(Long selectedDate) {
// user has selected a date
// format the date and set the text of the input box to be the selected date
// right now this format is hard-coded, this will change
;
// Get the offset from our timezone and UTC.
TimeZone timeZoneUTC = TimeZone.getDefault();
// It will be negative, so that's the -1
int offsetFromUTC = timeZoneUTC.getOffset(new Date().getTime()) * -1;
// Create a date format, then a date object with our offset
SimpleDateFormat simpleFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.US);
Date date = new Date(selectedDate + offsetFromUTC);
dataEntry.setText(simpleFormat.format(lDate));
}
});
picker.show(myActivity.getSupportFragmentManager(), picker.toString());