var spf = SimpleDateFormat("dd MMM yyyy")
val newDate = spf.parse("21 Agt 2022") // <- always error in this line
spf = SimpleDateFormat("yyyy-MM-dd")
val result = newDate?.let { it1 -> spf.format(it1) }.toString()
fun main(args: Array<String>) {
// prepare the locale your input was created in
val indonesia = Locale.forLanguageTag("id-ID")
// use it in your SimpleDateFormat
var spf = SimpleDateFormat("dd MMM yyyy", indonesia)
// parse the value
val newDate = spf.parse("21 Agt 2022")
// print the value
println(newDate)
}
fun main(args: Array<String>) {
// your input String
val input = "21 Agt 2022"
// prepare the locale your input uses
val indonesia = Locale.forLanguageTag("id-ID")
// prepare a DateTimeFormatter that considers Indonesian months