我想更改 Material Date Picker 的格式。我从 2021 年 4 月 13 日的字符串中得到它。但我想更改为 2021-04-13 格式。
Calendar calendar=Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.clear();
Long today= MaterialDatePicker.todayInUtcMilliseconds();
//materialDatePicker
MaterialDatePicker.Builder start_builder=MaterialDatePicker.Builder.datePicker();
start_builder.setTitleText("SELECT A START DATE");
start_builder.setSelection(today);
start_DatePicker=start_builder.build();
start_date.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
start_DatePicker.show(getSupportFragmentManager(),"Date_Picker");
}
});
start_DatePicker.addOnPositiveButtonClickListener(new MaterialPickerOnPositiveButtonClickListener() {
@Override
public void onPositiveButtonClick(Object selection) {
start_date.setText(start_DatePicker.getHeaderText());
String get_start_date=start_date.getText().toString();
DateFormat formatter = new SimpleDateFormat("yyyy MM dd");
String today = formatter.format(get_start_date);
String get_end_date=end_date.getText().toString();
Toast.makeText(this, "Start Date"+today + "End date" +get_end_date, Toast.LENGTH_SHORT).show();
}
});
}
我在下面有一个错误。无法将给定对象格式化为日期