-2

here is my code example

i have a material date picker which i want to use to get a date my problem is when i try to format it to 'yyyy-mm-dd' it always returns "00" in months for example if a string "Mar 5,2021" the result will be "2021-00-05" any help will be appreciated thank you

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
nissow
  • 69
  • 1
  • 8
  • 2
    Make sure you post your actual code in the question, not a picture. – Henry Twist Mar 28 '21 at 02:43
  • sorry i thaught a screen snip would be nicer – nissow Mar 28 '21 at 20:30
  • No problem, if you could [edit] your post that would be great. Then people in the future can be helped by your question. Also you can take a look at [ask] to see how to ask a good question. There is a section about not posting images of code. – Henry Twist Mar 28 '21 at 20:49

1 Answers1

0

The addOnPositiveButtonClickListener returns the selection as Long value. You don't need to get the HeaderText.

Use for example:

datePicker.addOnPositiveButtonClickListener {
    val utc = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
    utc.timeInMillis = it
    val format = SimpleDateFormat("yyyy-MM-dd")
    val formatted: String = format.format(utc.time)        
}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • yeah it works thank you sir, i cast the selection object to long and then formatted it as i wanted though "mm" must be upper case too – nissow Mar 28 '21 at 20:31