toLocalDateTime

fun String.toLocalDateTime(vararg formats: String?): LocalDateTime?

Works off of String representations of dateTime and parses through the following attempts in order when no format is present:

  • First, tries parsing as LocalDateTime with default parser
  • Lastly, if fails, tries parsing using a more flexible ISO 8601 format

When formats are provided, each format is attempted in-order until one succeeds.

Return

LocalDateTime? Null means couldn't parse, else parsed LocalDateTime.

Parameters

this

String representation of LocalDateTime.

formats

String? vararg of formats to attempt when parsing.