toLocalDateOrNull

fun String.toLocalDateOrNull(pattern: String = "EEE MMM dd HH:mm:ss zzz yyyy"): LocalDate?

Produce a LocalDate from the given strings value and pattern if possible.

Example:

"8/7/2022".toLocalDateOrNull("MM/dd/yyyy") // 2022-07-07
"Sun Aug 07 16:37:42 IRDT 2022".toLocalDateOrNull() // 2022-07-07
"7/2022".toLocalDateOrNull("MM/dd/yyyy") // null

Since

1.1.0

Return

A nullable LocalDate parsed from the string.

See also