I'm working with a String of date such as:
val date = "2021-01-24"
how can I convert that string in order to get "Sunday" (user local english) or "Domingo" (user local spanish)?
// Error I get using Dai answer
java.lang.IllegalArgumentException: Cannot format given Object as a Date
I'm using this code:
// Step 1: Parse the string with a defined format:
val tomorrowDateString = body.forecast.forecastday[1].date // -> "2021-01-24"
val parseTomorrow = LocalDate.parse(tomorrowDateString, DateTimeFormatter.ofPattern( "yyyy-MM-dd" ))
// Step 2: Format using the user's culture/locale settings:
val userFormat = java.text.DateFormat.getDateInstance( DateFormat.SHORT )
val tomorrow = userFormat.format(parseTomorrow)