toLocalDateTimeOrNull

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

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

Example:

"08/07/2022 13".toLocalDateTimeOrNull("MM/dd/yyyy HH") // 2022-08-07T13:00
"Sun Aug 07 16:37:42 IRDT 2022".toLocalDateTimeOrNull() // 2022-08-07T16:37:42
"7/2022".toLocalDateTimeOrNull("MM/dd/yyyy") // null

Since

1.1.0

Return

A nullable LocalDateTime parsed from the string.

See also