varselectedTime:TimePickerState? byremember{mutableStateOf(null)}// ...DialUseStateExample(onDismiss={showDialExample=false},onConfirm={time->
selectedTime=timeshowDialExample=false},)// ...if(selectedTime!=null){valcal=Calendar.getInstance()cal.set(Calendar.HOUR_OF_DAY,selectedTime!!.hour)cal.set(Calendar.MINUTE,selectedTime!!.minute)cal.isLenient=falseText("Selected time = ${formatter.format(cal.time)}")}else{Text("No time selected.")}
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-08-27 UTC。"],[],[],null,["[Time pickers](https://m3.material.io/components/time-pickers/overview) provide a way for users to select a time. You can\nuse the [`TimePicker`](/reference/kotlin/androidx/compose/material3/package-summary#TimePicker(androidx.compose.material3.TimePickerState,androidx.compose.ui.Modifier,androidx.compose.material3.TimePickerColors,androidx.compose.material3.TimePickerLayoutType)) and [`TimeInput`](/reference/kotlin/androidx/compose/material3/package-summary#TimeInput(androidx.compose.material3.TimePickerState,androidx.compose.ui.Modifier,androidx.compose.material3.TimePickerColors)) composables to implement a time\npicker in your app.\n| **Note:** `TimePicker` and `TimeInput` are experimental. File any issues on the [issue tracker](https://issuetracker.google.com/issues/new?component=856989&template=1425922).\n\nTypes\n\nThere are two types of time picker:\n\n- **Dial**: Lets users set a time by moving a handle around a dial.\n- **Input**: Lets users set a time using their keyboard.\n\nThe following image provides an example of a dial time picker on the left, and\nan input time picker on the right:\n**Figure 1.** A dial and an input time picker.\n\nAPI surface\n\nTo implement a time picker, use either the `TimePicker` or `TimeInput`\ncomposable:\n\n- [`TimePicker`](/reference/kotlin/androidx/compose/material3/package-summary#TimePicker(androidx.compose.material3.TimePickerState,androidx.compose.ui.Modifier,androidx.compose.material3.TimePickerColors,androidx.compose.material3.TimePickerLayoutType)): Implements a dial time picker.\n- [`TimeInput`](/reference/kotlin/androidx/compose/material3/package-summary#TimeInput(androidx.compose.material3.TimePickerState,androidx.compose.ui.Modifier,androidx.compose.material3.TimePickerColors)): Implements an input time picker.\n\n| **Note:** While they display different components, `TimePicker` and `TimeInput` are very similar composables in terms of their parameters. They are therefore largely interchangeable.\n\nState\n\nFor both `TimePicker` and `TimeInput`, you must also pass a\n[`TimePickerState`](/reference/kotlin/androidx/compose/material3/TimePickerState). This lets you set the default selected time that appears\non the picker. It also captures the time that the user has selected using the\npicker.\n\nDialog\n\nTime pickers appear in dialogs. The examples in this guide don't use dialogs.\nFor examples that do use dialogs, see the [Dialogs for time pickers](/develop/ui/compose/components/time-pickers-dialogs) guide.\n\nDial time picker\n\nThis snippet demonstrates how to implement a basic dial time picker.\n\n\n```kotlin\n@Composable\nfun DialExample(\n onConfirm: () -\u003e Unit,\n onDismiss: () -\u003e Unit,\n) {\n val currentTime = Calendar.getInstance()\n\n val timePickerState = rememberTimePickerState(\n initialHour = currentTime.get(Calendar.HOUR_OF_DAY),\n initialMinute = currentTime.get(Calendar.MINUTE),\n is24Hour = true,\n )\n\n Column {\n TimePicker(\n state = timePickerState,\n )\n Button(onClick = onDismiss) {\n Text(\"Dismiss picker\")\n }\n Button(onClick = onConfirm) {\n Text(\"Confirm selection\")\n }\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/TimePickers.kt#L178-L202\n```\n\n\u003cbr /\u003e\n\nConsider the following in this snippet:\n\n- `Calendar.getInstance()` initializes the `TimePickerState` with the current time.\n - This example uses `java.util.Calendar`. Enable [Java\n 8+ API desugaring](/studio/write/java8-support#library-desugaring) in your project to alternatively use `java.time.LocalTime` on all Android versions.\n- The `TimePicker` composable displays the time picker, taking `timePickerState` as a parameter.\n- The implementation includes two buttons: one to confirm the selection and another to dismiss the picker.\n\nThis implementation appears as follows:\n**Figure 2.** A dial time picker.\n\nInput time picker\n\nThis snippet demonstrates how to implement a basic input style time picker.\n\n\n```kotlin\n@Composable\nfun InputExample(\n onConfirm: () -\u003e Unit,\n onDismiss: () -\u003e Unit,\n) {\n val currentTime = Calendar.getInstance()\n\n val timePickerState = rememberTimePickerState(\n initialHour = currentTime.get(Calendar.HOUR_OF_DAY),\n initialMinute = currentTime.get(Calendar.MINUTE),\n is24Hour = true,\n )\n\n Column {\n TimeInput(\n state = timePickerState,\n )\n Button(onClick = onDismiss) {\n Text(\"Dismiss picker\")\n }\n Button(onClick = onConfirm) {\n Text(\"Confirm selection\")\n }\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/TimePickers.kt#L207-L231\n```\n\n\u003cbr /\u003e\n\nKey points to note in this implementation:\n\n- The structure is essentially the same the dial time picker, with the main difference being the use of `TimeInput` instead of `TimePicker`.\n- The `is24Hour` parameter for `timePickerState` is explicitly set to `true`. By default, this value is `false`.\n\nThis implementation appears as follows:\n**Figure 3.** An input time picker.\n\nUse the state\n\nTo make use of the time that the user has selected in a time picker, pass the\nappropriate `TimePickerState` to your `onConfirm` function. The parent\ncomposable can then access the selected time through `TimePickerState.hour` and\n`TimePickerState.minute`.\n\nThe following snippet demonstrates how to do this:\n\n\n```kotlin\n@Composable\nfun DialUseStateExample(\n onConfirm: (TimePickerState) -\u003e Unit,\n onDismiss: () -\u003e Unit,\n) {\n val currentTime = Calendar.getInstance()\n\n val timePickerState = rememberTimePickerState(\n initialHour = currentTime.get(Calendar.HOUR_OF_DAY),\n initialMinute = currentTime.get(Calendar.MINUTE),\n is24Hour = true,\n )\n\n Column {\n TimePicker(\n state = timePickerState,\n )\n Button(onClick = onDismiss) {\n Text(\"Dismiss picker\")\n }\n Button(onClick = { onConfirm(timePickerState) }) {\n Text(\"Confirm selection\")\n }\n }\n}https://github.com/android/snippets/blob/5673ffc60b614daf028ee936227128eb8c4f9781/compose/snippets/src/main/java/com/example/compose/snippets/components/TimePickers.kt#L236-L260\n```\n\n\u003cbr /\u003e\n\nYou could then call the composable like this: \n\n var selectedTime: TimePickerState? by remember { mutableStateOf(null) }\n\n // ...\n\n DialUseStateExample(\n onDismiss = {\n showDialExample = false\n },\n onConfirm = {\n time -\u003e\n selectedTime = time\n showDialExample = false\n },\n )\n\n // ...\n\n if (selectedTime != null) {\n val cal = Calendar.getInstance()\n cal.set(Calendar.HOUR_OF_DAY, selectedTime!!.hour)\n cal.set(Calendar.MINUTE, selectedTime!!.minute)\n cal.isLenient = false\n Text(\"Selected time = ${formatter.format(cal.time)}\")\n } else {\n Text(\"No time selected.\")\n }\n\nFor more detail, see the [full implementation in the snippets\napp](https://github.com/android/snippets/blob/main/compose/snippets/src/main/java/com/example/compose/snippets/components/TimePickers.kt).\n\nAdditional resources\n\n- [`TimePicker`](/reference/kotlin/androidx/compose/material3/package-summary#TimePicker(androidx.compose.material3.TimePickerState,androidx.compose.ui.Modifier,androidx.compose.material3.TimePickerColors,androidx.compose.material3.TimePickerLayoutType))\n- [Material Design - Time Pickers](https://m3.material.io/components/time-pickers/overview)"]]