Skip to content

//core/io.islandtime/toYear

toYear

common

fun YearMonth.toYear(): Year

Returns this year-month with the precision reduced to the year.

common

fun Date.toYear(): Year

Returns this date with the precision reduced to the year.

common

fun DateTime.toYear(): Year

fun OffsetDateTime.toYear(): Year

fun ZonedDateTime.toYear(): Year

Returns this date-time with the precision reduced to the year.

common

fun String.toYear(): Year

Converts a string to a Year.

The string is assumed to be an ISO-8601 year. For example, 2010, +002010, or Y12345. The output of Year.toString can be safely parsed using this method.

Throws

DateTimeParseException if parsing fails
DateTimeException if the parsed year is invalid

common

fun String.toYear(parser: DateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): Year

Converts a string to a Year using a specific parser.

A set of predefined parsers can be found in DateTimeParsers.

The parser must be capable of supplying DateTimeField.YEAR.

Throws

DateTimeParseException if parsing fails
DateTimeException if the parsed year is invalid