MonthNames

class MonthNames(val names: List<String>)(source)

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
constructor(january: String, february: String, march: String, april: String, may: String, june: String, july: String, august: String, september: String, october: String, november: String, december: String)

Create a MonthNames using the month names in order from January to December.

constructor(names: List<String>)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

A list of month names in order from January to December.