Kotlin Program to Convert String to Date.we will learn how to convert a string to a date in Kotlin. We will use the java.util.LocalDate class to convert a string to a Date.LocalDate comes with one static method parse that takes one date string as input and formats it as LocalDate object.
Kotlin Program to Convert String to Date
Source Code
import java.time.LocalDate
import java.time.format.DateTimeFormatter
fun main(args: Array<String>) {
// Format y-M-d or yyyy-MM-d
val string = "2020-07-25"
val date = LocalDate.parse(string, DateTimeFormatter.ISO_DATE)
println(date)
}
Output
Kotlin Program to Convert String to Date