Month Names
A description of how month names are formatted.
Instances of this class are typically used as arguments to DateTimeFormatBuilder.WithDate.monthName.
Predefined instances are available as ENGLISH_FULL and ENGLISH_ABBREVIATED. You can also create custom instances using the constructor.
An IllegalArgumentException will be thrown if some month name is empty or there are duplicate names.
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() {
//sampleStart
// Using strings for month names in a custom format
val format = LocalDate.Format {
monthName(MonthNames.ENGLISH_ABBREVIATED) // "Jan", "Feb", ...
char(' ')
dayOfMonth()
chars(", ")
year()
}
check(format.format(LocalDate(2021, 1, 13)) == "Jan 13, 2021")
//sampleEnd
}
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.test.*
fun main() {
//sampleStart
// Constructing a custom set of month names for parsing and formatting
val germanMonthNames = listOf(
"Januar", "Februar", "März", "April", "Mai", "Juni",
"Juli", "August", "September", "Oktober", "November", "Dezember"
)
// constructing by passing a list of 12 strings
val myMonthNamesFromList = MonthNames(germanMonthNames)
check(myMonthNamesFromList.names == germanMonthNames)
//sampleEnd
}
Constructors
Link copied to clipboard