core / io.islandtime / kotlin.String / toYearMonth

toYearMonth

(iosArm64) fun String.toYearMonth(): YearMonth
(iosX64) fun String.toYearMonth(): YearMonth
(jvm) fun String.toYearMonth(): YearMonth
(macosX64) fun String.toYearMonth(): YearMonth
(tvosArm64) fun String.toYearMonth(): YearMonth
(tvosX64) fun String.toYearMonth(): YearMonth
(watchosArm64) fun String.toYearMonth(): YearMonth
(watchosX86) fun String.toYearMonth(): YearMonth

Convert 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.

Exceptions

DateTimeParseException - if parsing fails

DateTimeException - if the parsed year-month is invalid

(iosArm64) fun String.toYearMonth(parser: DateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): YearMonth
(iosX64) fun String.toYearMonth(parser: DateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): YearMonth
(jvm) fun String.toYearMonth(parser: DateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): YearMonth
(macosX64) fun String.toYearMonth(parser: DateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): YearMonth
(tvosArm64) fun String.toYearMonth(parser: DateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): YearMonth
(tvosX64) fun String.toYearMonth(parser: DateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): YearMonth
(watchosArm64) fun String.toYearMonth(parser: DateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): YearMonth
(watchosX86) fun String.toYearMonth(parser: DateTimeParser, settings: DateTimeParserSettings = DateTimeParserSettings.DEFAULT): YearMonth

Convert 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.

Exceptions

DateTimeParseException - if parsing fails

DateTimeException - if the parsed year-month is invalid