0

Everyone

I'm using MaterialDatePicker to show the date and it was working fine and get the date like I want Aug 5,2021 and suddenly out of nowhere I get now Month like this M08 and that makes the date like this M08 5,2021

enter image description here

and below is the gradle dependency:

implementation "com.google.android.material:material:1.3.0"

Can anyone help me, please?

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51

2 Answers2

0

you can try this code

    private fun showDatePicker() {
        val selectedDateInMillis = currentSelectedDate ?: System.currentTimeMillis()
        
        MaterialDatePicker.Builder.datePicker().setSelection(selectedDateInMillis).build().apply {
            addOnPositiveButtonClickListener { dateInMillis -> onDateSelected(dateInMillis) }
        }.show(supportFragmentManager, MaterialDatePicker::class.java.canonicalName)
    }

    // result onDateSelected    
    private fun onDateSelected(dateTimeStampInMillis: Long) {
        currentSelectedDate = dateTimeStampInMillis
        val dateTime: LocalDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(currentSelectedDate), ZoneId.systemDefault())
        val dateAsFormattedText: String = dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))
        // view for result
        findViewById<TextView>(R.id.output).text = dateAsFormattedText
   }
sikurro
  • 375
  • 2
  • 6
0

I found the issue. It was a localization issue need to verify localization for the material date picker before using it.