Skip to content

//core/io.islandtime/toYearMonth

toYearMonth

common

fun Date.toYearMonth(): YearMonth

Returns this date with the precision reduced to the month.

common

fun DateTime.toYearMonth(): YearMonth

fun OffsetDateTime.toYearMonth(): YearMonth

fun ZonedDateTime.toYearMonth(): YearMonth

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

common

fun String.toYearMonth(): YearMonth

Converts a string to a YearMonth.

The string is assumed to be an ISO-8601 year-month. For example, 2010-05 or 1960-12. The output of YearMonth.toString can be safely parsed using this method.

Throws

DateTimeParseException if parsing fails
DateTimeException if the parsed year-month is invalid

common

fun String.toYearMonth(parser: DateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): YearMonth

Converts a string to a YearMonth using a specific parser.

A set of predefined parsers can be found in DateTimeParsers.

The parser must be capable of supplying DateTimeField.YEAR and DateTimeField.MONTH_OF_YEAR.

Throws

DateTimeParseException if parsing fails
DateTimeException if the parsed year-month is invalid