Month()

Anonymous contributor's avatar
Anonymous contributor
Published Nov 20, 2023
Contribute to Docs

The Month() method in Kotlin is used to retrieve the month from a given integer. This method is essential when working with date and time in Kotlin, allowing developers to extract and manipulate the month component of a date.

Syntax

val currMonth = Month(num)
  • currMonth: A month type value such as DECEMBER.
  • num: This is an integer representing the month extracted from the date object. Typically, in Kotlin, months are represented as integers ranging from 1 (January) to 12 (December).

Example

This example demonstrates the basic use of the Month() method.

import kotlinx.datetime.*
fun main() {
val currentMonth = Month(11)
println("The current month is: $currentMonth")
}

The output will be:

The current month is: NOVEMBER

All contributors

Contribute to Docs

Learn Kotlin on Codecademy