Skip to content

//core/io.islandtime/toOffsetDateTime

toOffsetDateTime

common

fun ZonedDateTime.toOffsetDateTime(): OffsetDateTime

Returns the combined date, time, and UTC offset.

While similar to ZonedDateTime, an OffsetDateTime representation is unaffected by time zone rule changes or database differences between systems, making it better suited for use cases involving persistence or network transfer.

common

fun String.toOffsetDateTime(): OffsetDateTime

Converts a string to an OffsetDateTime.

The string is assumed to be an ISO-8601 date-time with the UTC offset in extended format. For example, 2019-05-30T02:30+01:00. The output of OffsetDateTime.toString can be safely parsed using this method.

Throws

DateTimeParseException if parsing fails
DateTimeException if the parsed date-time or offset is invalid

common

fun String.toOffsetDateTime(parser: DateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): OffsetDateTime

Converts a string to an OffsetDateTime using a specific parser.

A set of predefined parsers can be found in DateTimeParsers.

Any custom parser must be capable of supplying the fields necessary to resolve a Date, Time and UtcOffset.

Throws

DateTimeParseException if parsing fails
DateTimeException if the parsed date-time or offset is invalid