.todayIn()

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

The .todayIn() method returns a date when called on a Clock while passing a TimeZone argument.

Syntax

myClock.todayIn(myTimeZone)
  • myClock: A Clock providing a source for Instants (e.g., 2023-11-21, 00:00:00 UTC+0). Clock.System is the clock that refers to the current platform for the current time.
  • myTimeZone: An instance of the TimeZone class (e.g., America/Los_Angeles).

Example

The example below demonstrates a basic implementation of .todayIn that returns the current date.

// Import all classes from kotlinx.datetime package.
import kotlinx.datetime.*
fun main() {
val myLocalDate = Clock.System.todayIn(timeZone = TimeZone.currentSystemDefault())
println(myLocalDate)
}

This example results in an output similar to the following:

2023-11-21

All contributors

Contribute to Docs

Learn Kotlin on Codecademy