DatePickerState


A state object that can be hoisted to observe the date picker state. See rememberDatePickerState.

Summary

Public properties

DisplayMode

A DisplayMode that represents the current UI mode (i.e. picker or input).

Cmn
Long

A timestamp that represents the currently displayed month start date in UTC milliseconds from the epoch.

Cmn
CalendarLocale

A locale that will be used when formatting dates, determining the input format, week-days, and more.

Cmn
SelectableDates

A SelectableDates that is consulted to check if a date is allowed.

Cmn
Long?

A timestamp that represents the selected date start of the day in UTC milliseconds from the epoch.

Cmn
IntRange

An IntRange that holds the year range that the date picker will be limited to.

Cmn

Extension functions

YearMonth?

Returns a YearMonth representation of the displayed month in this DatePickerState.

android
LocalDate?

Returns a LocalDate representation of the selected date in this DatePickerState, or null in case there is no selection.

android
Unit

Sets the DatePickerState.displayedMonthMillis based on a given YearMonth.

android
Unit

Sets the DatePickerState.selectedDateMillis based on a given LocalDate.

android

Public properties

displayMode

var displayModeDisplayMode

A DisplayMode that represents the current UI mode (i.e. picker or input).

displayedMonthMillis

var displayedMonthMillisLong

A timestamp that represents the currently displayed month start date in UTC milliseconds from the epoch.

Throws
kotlin.IllegalArgumentException

in case the value is set with a timestamp that does not fall within the yearRange.

locale

val localeCalendarLocale

A locale that will be used when formatting dates, determining the input format, week-days, and more.

selectableDates

val selectableDatesSelectableDates

A SelectableDates that is consulted to check if a date is allowed.

In case a date is not allowed to be selected, it will appear disabled in the UI.

selectedDateMillis

var selectedDateMillisLong?

A timestamp that represents the selected date start of the day in UTC milliseconds from the epoch.

Throws
kotlin.IllegalArgumentException

in case the value is set with a timestamp that does not fall within the yearRange.

yearRange

val yearRangeIntRange

An IntRange that holds the year range that the date picker will be limited to.

Extension functions

getDisplayedMonth

@RequiresApi(value = 26)
fun DatePickerState.getDisplayedMonth(): YearMonth?

Returns a YearMonth representation of the displayed month in this DatePickerState. The returned YearMonth is based on the DatePickerState.displayedMonthMillis, which represents midnight of the first day of the displayed month in UTC milliseconds from the epoch.

Returns
YearMonth?

The displayed YearMonth.

getSelectedDate

@RequiresApi(value = 26)
fun DatePickerState.getSelectedDate(): LocalDate?

Returns a LocalDate representation of the selected date in this DatePickerState, or null in case there is no selection.

Returns
LocalDate?

The selected LocalDate, or null if there is no selection.

setDisplayedMonth

@RequiresApi(value = 26)
fun DatePickerState.setDisplayedMonth(yearMonth: YearMonth): Unit

Sets the DatePickerState.displayedMonthMillis based on a given YearMonth.

Converts the YearMonth to the start of the first day of that month (midnight) in UTC and apply it to the DatePickerState displayedMonthMillis.

Parameters
yearMonth: YearMonth

The YearMonth to display.

setSelectedDate

@RequiresApi(value = 26)
fun DatePickerState.setSelectedDate(date: LocalDate?): Unit

Sets the DatePickerState.selectedDateMillis based on a given LocalDate.

Converts the LocalDate to the start of the day (midnight) in UTC and apply it to the DatePickerState selectedDateMillis. Setting null clears the selection.

Parameters
date: LocalDate?

The LocalDate to select, or null to clear the selection.