1e41f4b71Sopenharmony_ci# Time Picker Dialog Box (TimePickerDialog)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciA time picker dialog box is a dialog box that allows users to select a time from the 24-hour range through scrolling.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci>
9e41f4b71Sopenharmony_ci> The functionality of this module depends on UI context. This means that the APIs of this module cannot be used where the UI context is unclear. For details, see [UIContext](../js-apis-arkui-UIContext.md#uicontext).
10e41f4b71Sopenharmony_ci>
11e41f4b71Sopenharmony_ci> Since API version 10, you can use the [showTimePickerDialog](../js-apis-arkui-UIContext.md#showtimepickerdialog) API in [UIContext](../js-apis-arkui-UIContext.md#uicontext) to obtain the UI context.
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## TimePickerDialog.show
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_cistatic show(options?: TimePickerDialogOptions)
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciShows a time picker dialog box.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci**Parameters**
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci| Name | Type                                                       | Mandatory| Description                      |
26e41f4b71Sopenharmony_ci| ------- | ----------------------------------------------------------- | ---- | -------------------------- |
27e41f4b71Sopenharmony_ci| options | [TimePickerDialogOptions](#timepickerdialogoptions) | No  | Parameters of the time picker dialog box.|
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci## TimePickerDialogOptions
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ciInherited from [TimePickerOptions](ts-basic-components-timepicker.md#timepickeroptions).
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
36e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
37e41f4b71Sopenharmony_ci| useMilitaryTime | boolean | No| Whether to display time in 24-hour format. The 12-hour format is used by default.<br>Default value: **false**<br>**NOTE**<br>When in the 12-hour format, the AM/PM zone does not change depending on the hour portion.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
38e41f4b71Sopenharmony_ci| disappearTextStyle<sup>10+</sup> | [PickerTextStyle](ts-basic-components-datepicker.md#pickertextstyle10) | No| Font color, font size, and font weight for the top and bottom items.<br>Default value:<br>{<br>color: '#ff182431',<br>font: {<br>size: '14fp', <br>weight: FontWeight.Regular<br>}<br>}<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
39e41f4b71Sopenharmony_ci| textStyle<sup>10+</sup> | [PickerTextStyle](ts-basic-components-datepicker.md#pickertextstyle10) | No| Font color, font size, and font weight of all items except the top, bottom, and selected items.<br>Default value:<br>{<br>color: '#ff182431',<br>font: {<br>size: '16fp', <br>weight: FontWeight.Regular<br>}<br>}<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
40e41f4b71Sopenharmony_ci| selectedTextStyle<sup>10+</sup> | [PickerTextStyle](ts-basic-components-datepicker.md#pickertextstyle10) | No| Font color, font size, and font weight of the selected item.<br>Default value:<br>{<br>color: '#ff007dff',<br>font: {<br>size: '20vp', <br>weight: FontWeight.Medium<br>}<br>}<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
41e41f4b71Sopenharmony_ci| acceptButtonStyle<sup>12+</sup> | [PickerDialogButtonStyle](ts-methods-datepicker-dialog.md#pickerdialogbuttonstyle12) | No| Style of the accept button.<br>**NOTE**<br>In the **acceptButtonStyle** and **cancelButtonStyle** configurations, only one **primary** field can be set to **true** at most. If both the **primary** fields are set to **true**, neither will take effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
42e41f4b71Sopenharmony_ci| cancelButtonStyle<sup>12+</sup> | [PickerDialogButtonStyle](ts-methods-datepicker-dialog.md#pickerdialogbuttonstyle12) | No| Style of the cancel button.<br>**NOTE**<br>In the **acceptButtonStyle** and **cancelButtonStyle** configurations, only one **primary** field can be set to **true** at most. If both the **primary** fields are set to **true**, neither will take effect.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
43e41f4b71Sopenharmony_ci| alignment<sup>10+</sup>  | [DialogAlignment](ts-methods-alert-dialog-box.md#dialogalignment) | No  | Alignment mode of the dialog box in the vertical direction.<br>Default value: **DialogAlignment.Default**<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
44e41f4b71Sopenharmony_ci| offset<sup>10+</sup>     | [Offset](ts-types.md#offset) | No    | Offset of the dialog box based on the **alignment** settings.<br>Default value: **{ dx: 0 , dy: 0 }**<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
45e41f4b71Sopenharmony_ci| maskRect<sup>10+</sup>| [Rectangle](ts-methods-alert-dialog-box.md#rectangle8) | No    | Mask area of the dialog box. Events outside the mask area are transparently transmitted, and events within the mask area are not.<br>Default value: **{ x: 0, y: 0, width: '100%', height: '100%' }**<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
46e41f4b71Sopenharmony_ci| onAccept | (value: [TimePickerResult](ts-basic-components-timepicker.md#TimePickerResult)) => void | No| Callback invoked when the OK button in the dialog box is clicked.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
47e41f4b71Sopenharmony_ci| onCancel | () => void | No| Callback invoked when the Cancel button in the dialog box is clicked.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
48e41f4b71Sopenharmony_ci| onChange | (value: [TimePickerResult](ts-basic-components-timepicker.md#TimePickerResult)) => void | No| Callback invoked when the selected time changes.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
49e41f4b71Sopenharmony_ci| backgroundColor<sup>11+</sup> | [ResourceColor](ts-types.md#resourcecolor)  | No| Backplane color of the dialog box.<br>Default value: **Color.Transparent**<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
50e41f4b71Sopenharmony_ci| backgroundBlurStyle<sup>11+</sup> | [BlurStyle](ts-universal-attributes-background.md#blurstyle9) | No| Background blur style of the dialog box.<br>Default value: **BlurStyle.COMPONENT_ULTRA_THICK**<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
51e41f4b71Sopenharmony_ci| onDidAppear<sup>12+</sup> | () => void | No| Event callback when the dialog box appears.<br>**NOTE**<br>1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onAccept/onCancel/onChange) > onWillDisappear > onDidDisappear.<br>2. You can set the callback event for changing the dialog box display effect in **onDidAppear**. The settings take effect next time the dialog box appears.<br>3. If the user closes the dialog box immediately after it appears, **onWillDisappear** is invoked before **onDidAppear**.<br>4. If the dialog box is closed before its entrance animation is finished, this callback is not invoked.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
52e41f4b71Sopenharmony_ci| onDidDisappear<sup>12+</sup> | () => void | No| Event callback when the dialog box disappears.<br>**NOTE**<br>1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onAccept/onCancel/onChange) > onWillDisappear > onDidDisappear.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
53e41f4b71Sopenharmony_ci| onWillAppear<sup>12+</sup> | () => void | No| Event callback when the dialog box is about to appear.<br>**NOTE**<br>1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onAccept/onCancel/onChange) > onWillDisappear > onDidDisappear.<br>2. You can set the callback event for changing the dialog box display effect in **onWillAppear**. The settings take effect next time the dialog box appears.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
54e41f4b71Sopenharmony_ci| onWillDisappear<sup>12+</sup> | () => void | No| Event callback when the dialog box is about to disappear.<br>**NOTE**<br>1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onAccept/onCancel/onChange) > onWillDisappear > onDidDisappear.<br>2. If the user closes the dialog box immediately after it appears, **onWillDisappear** is invoked before **onDidAppear**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
55e41f4b71Sopenharmony_ci| shadow<sup>12+</sup>              | [ShadowOptions](ts-universal-attributes-image-effect.md#shadowoptions) \| [ShadowStyle](ts-universal-attributes-image-effect.md#shadowstyle10) | No  | Shadow of the dialog box.<br>Default value on 2-in-1 devices: **ShadowStyle.OUTER_FLOATING_MD** when the dialog box is focused and **ShadowStyle.OUTER_FLOATING_SM** otherwise<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
56e41f4b71Sopenharmony_ci| dateTimeOptions<sup>12+</sup> | [DateTimeOptions](../../apis-localization-kit/js-apis-intl.md#datetimeoptions) | No| Whether to display a leading zero for the hours and minutes. Currently only the configuration of the **hour** and **minute** parameters is supported.<br>Default value:<br>**hour**: In the 24-hour format, it defaults to **2-digit**, which means a leading zero is used; In the 12-hour format, it defaults to **numeric**, which means no leading zero is used.<br>**minute**: defaults to **2-digit**, which means a leading zero is used.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci## Example
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci### Example 1
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ciThis example shows the basic usage of **TimePickerDialog**.
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci```ts
65e41f4b71Sopenharmony_ci// xxx.ets
66e41f4b71Sopenharmony_ci@Entry
67e41f4b71Sopenharmony_ci@Component
68e41f4b71Sopenharmony_cistruct TimePickerDialogExample {
69e41f4b71Sopenharmony_ci  private selectTime: Date = new Date('2020-12-25T08:30:00')
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci  build() {
72e41f4b71Sopenharmony_ci    Column() {
73e41f4b71Sopenharmony_ci      Button ("TimePickerDialog 12-hour format")
74e41f4b71Sopenharmony_ci        .margin(20)
75e41f4b71Sopenharmony_ci        .onClick(() => {
76e41f4b71Sopenharmony_ci          TimePickerDialog.show({
77e41f4b71Sopenharmony_ci            selected: this.selectTime,
78e41f4b71Sopenharmony_ci            disappearTextStyle: { color: Color.Red, font: { size: 15, weight: FontWeight.Lighter } },
79e41f4b71Sopenharmony_ci            textStyle: { color: Color.Black, font: { size: 20, weight: FontWeight.Normal } },
80e41f4b71Sopenharmony_ci            selectedTextStyle: { color: Color.Blue, font: { size: 30, weight: FontWeight.Bolder } },
81e41f4b71Sopenharmony_ci            onAccept: (value: TimePickerResult) => {
82e41f4b71Sopenharmony_ci              // Set selectTime to the time when the OK button is clicked. In this way, when the dialog box is displayed again, the selected time is the time when the operation was confirmed last time.
83e41f4b71Sopenharmony_ci              if (value.hour != undefined && value.minute != undefined) {
84e41f4b71Sopenharmony_ci                this.selectTime.setHours(value.hour, value.minute)
85e41f4b71Sopenharmony_ci                console.info("TimePickerDialog:onAccept()" + JSON.stringify(value))
86e41f4b71Sopenharmony_ci              }
87e41f4b71Sopenharmony_ci            },
88e41f4b71Sopenharmony_ci            onCancel: () => {
89e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onCancel()")
90e41f4b71Sopenharmony_ci            },
91e41f4b71Sopenharmony_ci            onChange: (value: TimePickerResult) => {
92e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onChange()" + JSON.stringify(value))
93e41f4b71Sopenharmony_ci            },
94e41f4b71Sopenharmony_ci            onDidAppear: () => {
95e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onDidAppear()")
96e41f4b71Sopenharmony_ci            },
97e41f4b71Sopenharmony_ci            onDidDisappear: () => {
98e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onDidDisappear()")
99e41f4b71Sopenharmony_ci            },
100e41f4b71Sopenharmony_ci            onWillAppear: () => {
101e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onWillAppear()")
102e41f4b71Sopenharmony_ci            },
103e41f4b71Sopenharmony_ci            onWillDisappear: () => {
104e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onWillDisappear()")
105e41f4b71Sopenharmony_ci            }
106e41f4b71Sopenharmony_ci          })
107e41f4b71Sopenharmony_ci        })
108e41f4b71Sopenharmony_ci      Button ("TimePickerDialog 24-hour format")
109e41f4b71Sopenharmony_ci        .margin(20)
110e41f4b71Sopenharmony_ci        .onClick(() => {
111e41f4b71Sopenharmony_ci          TimePickerDialog.show({
112e41f4b71Sopenharmony_ci            selected: this.selectTime,
113e41f4b71Sopenharmony_ci            useMilitaryTime: true,
114e41f4b71Sopenharmony_ci            disappearTextStyle: { color: Color.Red, font: { size: 15, weight: FontWeight.Lighter } },
115e41f4b71Sopenharmony_ci            textStyle: { color: Color.Black, font: { size: 20, weight: FontWeight.Normal } },
116e41f4b71Sopenharmony_ci            selectedTextStyle: { color: Color.Blue, font: { size: 30, weight: FontWeight.Bolder } },
117e41f4b71Sopenharmony_ci            onAccept: (value: TimePickerResult) => {
118e41f4b71Sopenharmony_ci              if (value.hour != undefined && value.minute != undefined) {
119e41f4b71Sopenharmony_ci                this.selectTime.setHours(value.hour, value.minute)
120e41f4b71Sopenharmony_ci                console.info("TimePickerDialog:onAccept()" + JSON.stringify(value))
121e41f4b71Sopenharmony_ci              }
122e41f4b71Sopenharmony_ci            },
123e41f4b71Sopenharmony_ci            onCancel: () => {
124e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onCancel()")
125e41f4b71Sopenharmony_ci            },
126e41f4b71Sopenharmony_ci            onChange: (value: TimePickerResult) => {
127e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onChange()" + JSON.stringify(value))
128e41f4b71Sopenharmony_ci            },
129e41f4b71Sopenharmony_ci            onDidAppear: () => {
130e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onDidAppear()")
131e41f4b71Sopenharmony_ci            },
132e41f4b71Sopenharmony_ci            onDidDisappear: () => {
133e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onDidDisappear()")
134e41f4b71Sopenharmony_ci            },
135e41f4b71Sopenharmony_ci            onWillAppear: () => {
136e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onWillAppear()")
137e41f4b71Sopenharmony_ci            },
138e41f4b71Sopenharmony_ci            onWillDisappear: () => {
139e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onWillDisappear()")
140e41f4b71Sopenharmony_ci            }
141e41f4b71Sopenharmony_ci          })
142e41f4b71Sopenharmony_ci        })
143e41f4b71Sopenharmony_ci    }.width('100%')
144e41f4b71Sopenharmony_ci  }
145e41f4b71Sopenharmony_ci}
146e41f4b71Sopenharmony_ci```
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci![TimetPickerDialog](figures/TimePickerDialog.gif)
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci
151e41f4b71Sopenharmony_ci### Example 2
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ciThis example shows how to customize the button style.
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci```ts
156e41f4b71Sopenharmony_ci// xxx.ets
157e41f4b71Sopenharmony_ci@Entry
158e41f4b71Sopenharmony_ci@Component
159e41f4b71Sopenharmony_cistruct TimePickerDialogExample {
160e41f4b71Sopenharmony_ci  private selectTime: Date = new Date('2020-12-25T08:30:00')
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci  build() {
163e41f4b71Sopenharmony_ci    Column() {
164e41f4b71Sopenharmony_ci      Button ("TimePickerDialog 24-hour format")
165e41f4b71Sopenharmony_ci        .margin(20)
166e41f4b71Sopenharmony_ci        .onClick(() => {
167e41f4b71Sopenharmony_ci          TimePickerDialog.show({
168e41f4b71Sopenharmony_ci            selected: this.selectTime,
169e41f4b71Sopenharmony_ci            useMilitaryTime: true,
170e41f4b71Sopenharmony_ci            disappearTextStyle: { color: Color.Red, font: { size: 15, weight: FontWeight.Lighter } },
171e41f4b71Sopenharmony_ci            textStyle: { color: Color.Black, font: { size: 20, weight: FontWeight.Normal } },
172e41f4b71Sopenharmony_ci            selectedTextStyle: { color: Color.Blue, font: { size: 30, weight: FontWeight.Bolder } },
173e41f4b71Sopenharmony_ci            acceptButtonStyle: { type: ButtonType.Normal, style: ButtonStyleMode.NORMAL, role: ButtonRole.NORMAL, fontColor: Color.Red,
174e41f4b71Sopenharmony_ci              fontSize: '26fp', fontWeight: FontWeight.Bolder, fontStyle: FontStyle.Normal, fontFamily: 'sans-serif', backgroundColor:'#80834511',
175e41f4b71Sopenharmony_ci              borderRadius: 20 },
176e41f4b71Sopenharmony_ci            cancelButtonStyle: { type: ButtonType.Normal, style: ButtonStyleMode.NORMAL, role: ButtonRole.NORMAL, fontColor: Color.Blue,
177e41f4b71Sopenharmony_ci              fontSize: '16fp', fontWeight: FontWeight.Normal, fontStyle: FontStyle.Italic, fontFamily: 'sans-serif', backgroundColor:'#50182431',
178e41f4b71Sopenharmony_ci              borderRadius: 10 },
179e41f4b71Sopenharmony_ci            onAccept: (value: TimePickerResult) => {
180e41f4b71Sopenharmony_ci              if (value.hour != undefined && value.minute != undefined) {
181e41f4b71Sopenharmony_ci                this.selectTime.setHours(value.hour, value.minute)
182e41f4b71Sopenharmony_ci                console.info("TimePickerDialog:onAccept()" + JSON.stringify(value))
183e41f4b71Sopenharmony_ci              }
184e41f4b71Sopenharmony_ci            },
185e41f4b71Sopenharmony_ci            onCancel: () => {
186e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onCancel()")
187e41f4b71Sopenharmony_ci            },
188e41f4b71Sopenharmony_ci            onChange: (value: TimePickerResult) => {
189e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onChange()" + JSON.stringify(value))
190e41f4b71Sopenharmony_ci            },
191e41f4b71Sopenharmony_ci            onDidAppear: () => {
192e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onDidAppear()")
193e41f4b71Sopenharmony_ci            },
194e41f4b71Sopenharmony_ci            onDidDisappear: () => {
195e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onDidDisappear()")
196e41f4b71Sopenharmony_ci            },
197e41f4b71Sopenharmony_ci            onWillAppear: () => {
198e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onWillAppear()")
199e41f4b71Sopenharmony_ci            },
200e41f4b71Sopenharmony_ci            onWillDisappear: () => {
201e41f4b71Sopenharmony_ci              console.info("TimePickerDialog:onWillDisappear()")
202e41f4b71Sopenharmony_ci            }
203e41f4b71Sopenharmony_ci          })
204e41f4b71Sopenharmony_ci        })
205e41f4b71Sopenharmony_ci    }.width('100%')
206e41f4b71Sopenharmony_ci  }
207e41f4b71Sopenharmony_ci}
208e41f4b71Sopenharmony_ci```
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ci![TimetPickerDialog](figures/TimePickerDialog_CustomButton.png)
211