我正在尝试从 DatePicker 获取所选日期,但我总是比所选日期少一天
例如,如果我选择 14/2/2022 我获得 13/2/2022,如果我选择 8/10/2018 我获得 7/10/2018
这是我的代码:
private fun DatePickerSelected() {
val picker = MaterialDatePicker.Builder.datePicker()
.setTitleText("Select date of birth")
.setSelection(MaterialDatePicker.todayInUtcMilliseconds())
.build()
picker.addOnPositiveButtonClickListener {
val date = Date(picker.selection!!)
Log.d("Date",date.toString())
val dateString = SimpleDateFormat("dd/MM/yyyy").format(date)
binding.edtBirthday.editText?.setText(dateString)
}
picker.show(requireActivity().supportFragmentManager, "BirthdayPicker")
}
哪个是问题?谢谢!