# Date Picker Dialog Box (DatePickerDialog)
A date picker dialog box is a dialog box that allows users to select a date from the given range.
> **NOTE**
>
> - The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
>
> - 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](../../../ui/arkts-global-interface.md). For details, see [UIContext](../arkts-apis-uicontext-uicontext.md).
## DatePickerDialog
### show(deprecated)
static show(options?: DatePickerDialogOptions)
Shows a date picker dialog box.
> **NOTE**
>
> This API is deprecated since API version 18. You are advised to use [showDatePickerDialog](../arkts-apis-uicontext-uicontext.md#showdatepickerdialog) in [UIContext](../arkts-apis-uicontext-uicontext.md) instead.
>
> Since API version 10, you can use the [showDatePickerDialog](../arkts-apis-uicontext-uicontext.md#showdatepickerdialog) API in [UIContext](../arkts-apis-uicontext-uicontext.md), which ensures that the date picker dialog box is shown in the intended UI instance.
**Atomic service API**: This API can be used in atomic services since API version 11.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
**Device behavior differences**: On wearables, calling this API results in a runtime exception indicating that the API is undefined. On other devices, the API works correctly.
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ----------------------------------------------------------- | ---- | -------------------------- |
| options | [DatePickerDialogOptions](#datepickerdialogoptions) | No | Parameters of the date picker dialog box.|
## DatePickerDialogOptions
Defines the configuration options of the date picker dialog box.
Inherited from [DatePickerOptions](ts-basic-components-datepicker.md#datepickeroptions).
**System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name| Type| Read-Only| Optional| Description|
| -------- | -------- | -------- | -------- | -------- |
| lunar | boolean | No| Yes| Whether to display the lunar calendar. The value **true** means to display the lunar calendar, and **false** means the opposite.
Default value: **false**
**Atomic service API**: This API can be used in atomic services since API version 11.|
| showTime10+ | boolean | No| Yes| Whether to display the time item. The value **true** means to display the time item, and **false** means the opposite.
Default value: **false**
With **showTime=true**, the **mode** parameter has no effect and the default three columns for year, month, and day are displayed.
**Atomic service API**: This API can be used in atomic services since API version 11.|
| useMilitaryTime10+ | boolean | No| Yes| Whether to display time in 24-hour format. The value **true** means to display time in 24-hour format, and **false** means the opposite.
Default value: **false**
**NOTE**
When the display time is in 12-hour format, the AM/PM zone does not change depending on the hour portion.
**Atomic service API**: This API can be used in atomic services since API version 11.|
| lunarSwitch10+ | boolean | No| Yes| Whether to display the lunar calendar switch. The value **true** means to display the lunar calendar switch, and **false** means the opposite.
Default value: **false**
**Atomic service API**: This API can be used in atomic services since API version 11.|
| lunarSwitchStyle14+ | [LunarSwitchStyle](#lunarswitchstyle14) | No| Yes| Style of the lunar calendar switch.
Default value: **{ selectedColor: $r('sys.color.ohos_id_color_text_primary_actived'), unselectedColor: $r('sys.color.ohos_id_color_switch_outline_off'), strokeColor: Color.White }**
**Atomic service API**: This API can be used in atomic services since API version 14.|
| disappearTextStyle10+ | [PickerTextStyle](ts-picker-common.md#pickertextstyle) | No| Yes| Text color, font size, and font weight of the items located two positions above or below the selected item.
Default value:
{
color: '#ff182431',
font: {
size: '14fp',
weight: FontWeight.Regular
}
}
**Atomic service API**: This API can be used in atomic services since API version 11.|
| textStyle10+ | [PickerTextStyle](ts-picker-common.md#pickertextstyle) | No| Yes| Text color, font size, and font weight of the items located one position above or below the selected item.
Default value:
{
color: '#ff182431',
font: {
size: '16fp',
weight: FontWeight.Regular
}
}
**Atomic service API**: This API can be used in atomic services since API version 11.|
| selectedTextStyle10+ | [PickerTextStyle](ts-picker-common.md#pickertextstyle) | No| Yes| Text color, font size, and font weight of the selected item.
Default value:
{
color: '#ff007dff',
font: {
size: '20fp',
weight: FontWeight.Medium
}
}
**Atomic service API**: This API can be used in atomic services since API version 11.|
| acceptButtonStyle12+ | [PickerDialogButtonStyle](ts-picker-common.md#pickerdialogbuttonstyle12) | No| Yes| Style of the accept button.
**NOTE**
1. In **acceptButtonStyle** and **cancelButtonStyle**, at most one **primary** field can be set to **true**. If both are set to **true**, the **primary** field will remain at the default value of **false**.
2. The default button height is 40 vp and remains fixed even in accessibility and large-font modes. In addition, even if the button style is set to [ROUNDED_RECTANGLE](ts-basic-components-button.md#buttontype), the displayed effect is still a capsule button ([Capsule](ts-basic-components-button.md#buttontype)).
**Atomic service API**: This API can be used in atomic services since API version 12.|
| cancelButtonStyle12+ | [PickerDialogButtonStyle](ts-picker-common.md#pickerdialogbuttonstyle12) | No| Yes| Style of the cancel button.
**NOTE**
1. In **acceptButtonStyle** and **cancelButtonStyle**, at most one **primary** field can be set to **true**. If both are set to **true**, the **primary** field will remain at the default value of **false**.
2. The default button height is 40 vp and remains fixed even in accessibility and large-font modes. In addition, even if the button style is set to [ROUNDED_RECTANGLE](ts-basic-components-button.md#buttontype), the displayed effect is still a capsule button ([Capsule](ts-basic-components-button.md#buttontype)).
**Atomic service API**: This API can be used in atomic services since API version 12.|
| alignment10+ | [DialogAlignment](ts-methods-alert-dialog-box.md#dialogalignment) | No | Yes | Alignment mode of the dialog box in the vertical direction.
Default value: **DialogAlignment.Default**
**Atomic service API**: This API can be used in atomic services since API version 11.|
| offset10+ | [Offset](ts-types.md#offset) | No | Yes | Offset of the dialog box based on the **alignment** settings.
Default value: **{ dx: 0 , dy: 0 }**
**Atomic service API**: This API can be used in atomic services since API version 11.|
| maskRect10+| [Rectangle](ts-methods-alert-dialog-box.md#rectangle8) | No | Yes | Mask area of the dialog box. Events outside the mask area are transparently transmitted, and events within the mask area are not.
Default value: **{ x: 0, y: 0, width: '100%', height: '100%' }**
**Atomic service API**: This API can be used in atomic services since API version 11.|
| onAccept(deprecated) | (value: [DatePickerResult](ts-basic-components-datepicker.md#datepickerresult)) => void | No| Yes| Callback invoked when the OK button in the dialog box is clicked.
**NOTE**
This API is supported since API version 8 and deprecated since API version 10. You are advised to use **onDateAccept** instead.|
| onCancel | [VoidCallback](ts-types.md#voidcallback12) | No| Yes| Callback invoked when the Cancel button in the dialog box is clicked.
**Atomic service API**: This API can be used in atomic services since API version 11.|
| onChange(deprecated) | (value: [DatePickerResult](ts-basic-components-datepicker.md#datepickerresult)) => void | No| Yes| Callback invoked when the selected item in the picker changes.
**NOTE**
This API is supported since API version 8 and deprecated since API version 10. You are advised to use **onDateChange** instead.|
| onDateAccept10+ | [Callback](ts-types.md#callback12)\ | No| Yes| Callback invoked when the OK button in the dialog box is clicked.
**NOTE**
When **showTime** is set to **true**, the hour and minute in the value returned by the callback are the hour and minute selected in the picker. Otherwise, the hour and minute are the hour and minute of the system time.
**Atomic service API**: This API can be used in atomic services since API version 11.|
| onDateChange10+ | [Callback](ts-types.md#callback12)\ | No| Yes| Callback invoked when the selected item in the picker changes.
**NOTE**
When **showTime** is set to **true**, the hour and minute in the value returned by the callback are the hour and minute selected in the picker. Otherwise, the hour and minute are the hour and minute of the system time.
**Atomic service API**: This API can be used in atomic services since API version 11.|
| backgroundColor11+ | [ResourceColor](ts-types.md#resourcecolor) | No| Yes| Backplane color of the dialog box.
Default value: **Color.Transparent**
**NOTE**
When **backgroundColor** is set to a non-transparent color, **backgroundBlurStyle** must be set to **BlurStyle.NONE**; otherwise, the color display may not meet the expected effect.
**Atomic service API**: This API can be used in atomic services since API version 12.|
| backgroundBlurStyle11+ | [BlurStyle](ts-universal-attributes-background.md#blurstyle9) | No| Yes| Background blur style of the dialog box.
Default value: **BlurStyle.COMPONENT_ULTRA_THICK**
**NOTE**
Setting this parameter to **BlurStyle.NONE** disables the background blur. When **backgroundBlurStyle** is set to a value other than **NONE**, do not set **backgroundColor**. If you do, the color display may not produce the expected visual effect.
**Atomic service API**: This API can be used in atomic services since API version 12.|
| backgroundBlurStyleOptions19+ | [BackgroundBlurStyleOptions](ts-universal-attributes-background.md#backgroundblurstyleoptions10) | No| Yes| Options for customizing the background blur style.
**Atomic service API**: This API can be used in atomic services since API version 19.|
| backgroundEffect19+ | [BackgroundEffectOptions](ts-universal-attributes-background.md#backgroundeffectoptions11) | No| Yes| Options for customizing the background effect.
**Atomic service API**: This API can be used in atomic services since API version 19.|
| onDidAppear12+ | [VoidCallback](ts-types.md#voidcallback12) | No| Yes| Event callback when the dialog box appears.
**NOTE**
1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onDateAccept/onCancel/onDateChange) > onWillDisappear > onDidDisappear.
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.
3. If the user closes the dialog box immediately after it appears, **onWillDisappear** is invoked before **onDidAppear**.
4. If the dialog box is closed before its entrance animation is finished, this callback is not invoked.
**Atomic service API**: This API can be used in atomic services since API version 12.|
| onDidDisappear12+ | [VoidCallback](ts-types.md#voidcallback12) | No| Yes| Event callback when the dialog box disappears.
**NOTE**
1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onDateAccept/onCancel/onDateChange) > onWillDisappear > onDidDisappear.
**Atomic service API**: This API can be used in atomic services since API version 12.|
| onWillAppear12+ | [VoidCallback](ts-types.md#voidcallback12) | No| Yes| Event callback when the dialog box is about to appear.
**NOTE**
1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onDateAccept/onCancel/onDateChange) > onWillDisappear > onDidDisappear.
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.
**Atomic service API**: This API can be used in atomic services since API version 12.|
| onWillDisappear12+ | [VoidCallback](ts-types.md#voidcallback12) | No| Yes| Event callback when the dialog box is about to disappear.
**NOTE**
1. The normal timing sequence is as follows: onWillAppear > onDidAppear > (onDateAccept/onCancel/onDateChange) > onWillDisappear > onDidDisappear.
2. If the user closes the dialog box immediately after it appears, **onWillDisappear** is invoked before **onDidAppear**.
**Atomic service API**: This API can be used in atomic services since API version 12.|
| shadow12+ | [ShadowOptions](ts-universal-attributes-image-effect.md#shadowoptions) \| [ShadowStyle](ts-universal-attributes-image-effect.md#shadowstyle10) | No | Yes | Shadow of the dialog box.
Default value on 2-in-1 devices: **ShadowStyle.OUTER_FLOATING_MD** when the dialog box is focused and **ShadowStyle.OUTER_FLOATING_SM** otherwise
**Atomic service API**: This API can be used in atomic services since API version 12.|
| dateTimeOptions12+ | [DateTimeOptions](../../apis-localization-kit/js-apis-intl.md#datetimeoptionsdeprecated) | No| Yes| Whether to display a leading zero for the hours and minutes. Only the configuration of the **hour** and **minute** parameters is supported.
Default value:
**hour**: For the 24-hour format, the default value is **"2-digit"**, meaning the hour is displayed as a two-digit number. If the actual value is less than 10, a leading zero is added, displayed as "0X". For the 12-hour format, the default value is **"numeric"**, meaning no leading zero.
**minute**: The default value is **"2-digit"**, meaning the minute is displayed as a two-digit number. If the actual value is less than 10, a leading zero is added, displayed as "0X".
**Atomic service API**: This API can be used in atomic services since API version 12.|
| enableHoverMode14+ | boolean | No | Yes | Whether to respond when the device is in semi-folded mode.
Default value: **false**. The value **true** means to respond when the device is in semi-folded mode, and **false** means the opposite.
**Atomic service API**: This API can be used in atomic services since API version 14.|
| hoverModeArea14+ | [HoverModeAreaType](ts-appendix-enums.md#hovermodeareatype14) | No | Yes | Display area of the dialog box when the device is in semi-folded mode.
Default value: **HoverModeAreaType.BOTTOM_SCREEN**
**Atomic service API**: This API can be used in atomic services since API version 14.|
| enableHapticFeedback18+ | boolean | No | Yes | Whether to enable haptic feedback.
The value **true** means to enable haptic feedback, and **false** means the opposite. The default value is **true**.
**Atomic service API**: This API can be used in atomic services since API version 18.
**NOTE**
To enable haptic feedback, you must declare the ohos.permission.VIBRATE permission under **requestPermissions** in the **module.json5** file of the project.
"requestPermissions": [{"name": "ohos.permission.VIBRATE"}]|
| canLoop20+ | boolean | No| Yes| Whether to enable cyclic scrolling.
Default value: **true**.
**NOTE**
**true**: Cyclic scrolling is enabled, where the year values increment or decrement with month cycling, and month values increment or decrement with day cycling.
**false**: Cyclic scrolling is disabled, preventing out-of-bounds scrolling in year, month, and day columns and cross-column value synchronization.
**Atomic service API**: This API can be used in atomic services since API version 20.|
## LunarSwitchStyle14+
Defines the style of the lunar calendar switch in the **DatePickerDialog** component.
**Atomic service API**: This API can be used in atomic services since API version 14.
**System capability**: SystemCapability.ArkUI.ArkUI.Full
| Name | Type | Read-Only| Optional| Description |
| ------ |-------------------|-----|----------|----------|
| selectedColor| [ResourceColor](ts-types.md#resourcecolor) | No | Yes | Background color of the switch when it is on.
Default value: **$r('sys.color.ohos_id_color_text_primary_actived')**|
| unselectedColor | [ResourceColor](ts-types.md#resourcecolor) | No | Yes | Border color of the switch when it is off.
Default value: **$r('sys.color.ohos_id_color_switch_outline_off')**|
| strokeColor | [ResourceColor](ts-types.md#resourcecolor) | No | Yes | Color of the icon inside the switch.
Default value: **Color.White**|
**Handling in the case of exceptions**
| Exception | Result |
| -------- | ------------------------------------------------------------ |
| The start date is later than the end date, and the selected date is not set. | The start date, end date, and selected date are set to the default values. |
| The start date is later than the end date, and the selected date is earlier than the default start date. | The start date and end date are set to the default values, and the selected date is set to the default start date. |
| The start date is later than the end date, and the selected date is later than the default end date. | The start date and end date are set to the default values, and the selected date is set to the default end date. |
| The start date is later than the end date, and the selected date is within the range of the default start date and end date. | The start date and end date are set to the default values, and the selected date is set to the specified value.|
| The selected date is earlier than the start date. | The selected date is set to the start date. |
| The selected date is later than the end date. | The selected date is set to the end date. |
| The start date is later than the current system date, and the selected date is not set. | The selected date is set to the start date. |
| The end date is earlier than the current system date, and the selected date is not set. | The selected date is set to the end date. |
| The set date is in invalid format, for example, **'1999-13-32'**. | The default value is used. |
| The start date or end date is earlier than the valid date range. | The start date or end date is set to the earliest date in the valid date range. |
| The start date or end date is later than the valid date range. | The start date or end date is set to the latest date in the valid date range. |
The valid date range is from 1900-1-31 to 2100-12-31.
The exception detection and handling with the selected date comes after that with the start date and end date.
## Example
> **NOTE**
>
> For clarity in UI execution context, you are advised to use the [showDatePickerDialog](../arkts-apis-uicontext-uicontext.md#showdatepickerdialog) API in [UIContext](../arkts-apis-uicontext-uicontext.md).
### Example 1: Setting the Display Time
This example demonstrates how to set the display time using **showTime**, **useMilitaryTime**, and **dateTimeOptions**.
```ts
// xxx.ets
@Entry
@Component
struct DatePickerDialogExample {
selectedDate: Date = new Date("2010-1-1");
build() {
Column() {
Button("DatePickerDialog")
.margin(20)
.onClick(() => {
this.getUIContext().showDatePickerDialog({
start: new Date("2000-1-1"),
end: new Date("2100-12-31"),
selected: this.selectedDate,
showTime: true,
useMilitaryTime: false,
dateTimeOptions: { hour: "numeric", minute: "2-digit" },
onDateAccept: (value: Date) => {
// Use the setFullYear method to set the date when the OK button is touched. In this way, when the date picker dialog box is displayed again, the selected date is the date last confirmed.
this.selectedDate = value;
console.info("DatePickerDialog:onDateAccept()" + value.toString());
},
onCancel: () => {
console.info("DatePickerDialog:onCancel()");
},
onDateChange: (value: Date) => {
console.info("DatePickerDialog:onDateChange()" + value.toString());
},
onDidAppear: () => {
console.info("DatePickerDialog:onDidAppear()");
},
onDidDisappear: () => {
console.info("DatePickerDialog:onDidDisappear()");
},
onWillAppear: () => {
console.info("DatePickerDialog:onWillAppear()");
},
onWillDisappear: () => {
console.info("DatePickerDialog:onWillDisappear()");
}
})
})
}.width('100%')
}
}
```

### Example 2: Customizing the Style
In this example, **disappearTextStyle**, **textStyle**, **selectedTextStyle**, **acceptButtonStyle**, and **cancelButtonStyle** are configured to customize the text and button style.
```ts
// xxx.ets
@Entry
@Component
struct DatePickerDialogExample {
selectedDate: Date = new Date("2010-1-1");
build() {
Column() {
Button("DatePickerDialog")
.margin(20)
.onClick(() => {
this.getUIContext().showDatePickerDialog({
start: new Date("2000-1-1"),
end: new Date("2100-12-31"),
selected: this.selectedDate,
disappearTextStyle: { color: '#297bec', font: { size: '20fp', weight: FontWeight.Bold } },
textStyle: { color: Color.Black, font: { size: '18fp', weight: FontWeight.Normal } },
selectedTextStyle: { color: Color.Blue, font: { size: '26fp', weight: FontWeight.Regular } },
acceptButtonStyle: {
type: ButtonType.Normal,
style: ButtonStyleMode.NORMAL,
role: ButtonRole.NORMAL,
fontColor: 'rgb(81, 81, 216)',
fontSize: '26fp',
fontWeight: FontWeight.Bolder,
fontStyle: FontStyle.Normal,
fontFamily: 'sans-serif',
backgroundColor: '#A6ACAF',
borderRadius: 20
},
cancelButtonStyle: {
type: ButtonType.Normal,
style: ButtonStyleMode.NORMAL,
role: ButtonRole.NORMAL,
fontColor: Color.Blue,
fontSize: '16fp',
fontWeight: FontWeight.Normal,
fontStyle: FontStyle.Italic,
fontFamily: 'sans-serif',
backgroundColor: '#50182431',
borderRadius: 10
},
onDateAccept: (value: Date) => {
// Use the setFullYear method to set the date when the OK button is touched. In this way, when the date picker dialog box is displayed again, the selected date is the date last confirmed.
this.selectedDate = value;
console.info("DatePickerDialog:onDateAccept()" + value.toString());
},
onCancel: () => {
console.info("DatePickerDialog:onCancel()");
},
onDateChange: (value: Date) => {
console.info("DatePickerDialog:onDateChange()" + value.toString());
},
onDidAppear: () => {
console.info("DatePickerDialog:onDidAppear()");
},
onDidDisappear: () => {
console.info("DatePickerDialog:onDidDisappear()");
},
onWillAppear: () => {
console.info("DatePickerDialog:onWillAppear()");
},
onWillDisappear: () => {
console.info("DatePickerDialog:onWillDisappear()");
}
});
})
}.width('100%')
}
}
```

> **NOTE**
>
> To implement a fully customized date picker dialog box, create a [custom dialog box](ts-methods-custom-dialog-box.md) and then implement the [DatePicker](ts-basic-components-datepicker.md) component.
### Example 3: Configuring a Dialog Box in the Hover State
This example demonstrates how to set the layout area of a dialog box when the device is in semi-folded mode.
```ts
@Entry
@Component
struct DatePickerDialogExample {
selectedDate: Date = new Date("2010-1-1");
build() {
Column() {
Button("DatePickerDialog")
.margin(20)
.onClick(() => {
this.getUIContext().showDatePickerDialog({
start: new Date("2000-1-1"),
end: new Date("2100-12-31"),
selected: this.selectedDate,
showTime: true,
useMilitaryTime: false,
disappearTextStyle: { color: Color.Pink, font: { size: '22fp', weight: FontWeight.Bold }},
textStyle: { color: '#ff00ff00', font: { size: '18fp', weight: FontWeight.Normal }},
selectedTextStyle: { color: '#ff182431', font: { size: '14fp', weight: FontWeight.Regular }},
onDateAccept: (value: Date) => {
// Use the setFullYear method to set the date when the OK button is touched. In this way, when the date picker dialog box is displayed again, the selected date is the date last confirmed.
this.selectedDate = value;
console.info("DatePickerDialog:onDateAccept()" + value.toString());
},
onCancel: () => {
console.info("DatePickerDialog:onCancel()");
},
onDateChange: (value: Date) => {
console.info("DatePickerDialog:onDateChange()" + value.toString());
},
onDidAppear: () => {
console.info("DatePickerDialog:onDidAppear()");
},
onDidDisappear: () => {
console.info("DatePickerDialog:onDidDisappear()");
},
onWillAppear: () => {
console.info("DatePickerDialog:onWillAppear()");
},
onWillDisappear: () => {
console.info("DatePickerDialog:onWillDisappear()");
},
enableHoverMode: true,
hoverModeArea: HoverModeAreaType.TOP_SCREEN
});
})
}.width('100%')
}
}
```
### Example 4: Setting the Dialog Box Position
This example demonstrates how to set the position of a dialog box using **alignment** and **offset**.
```ts
// xxx.ets
@Entry
@Component
struct DatePickerDialogExample {
selectedDate: Date = new Date("2010-1-1");
build() {
Column() {
Button("DatePickerDialog")
.margin(20)
.onClick(() => {
this.getUIContext().showDatePickerDialog({
start: new Date("2000-1-1"),
end: new Date("2100-12-31"),
selected: this.selectedDate,
alignment: DialogAlignment.Center,
offset: { dx: 20, dy: 0 },
onDateAccept: (value: Date) => {
// Use the setFullYear method to set the date when the OK button is touched. In this way, when the date picker dialog box is displayed again, the selected date is the date last confirmed.
this.selectedDate = value;
console.info("DatePickerDialog:onDateAccept()" + value.toString());
}
});
})
}.width('100%')
}
}
```
### Example 5: Setting the Mask Area
This example demonstrates how to set the mask area using **maskRect**.
```ts
// xxx.ets
@Entry
@Component
struct DatePickerDialogExample {
selectedDate: Date = new Date("2010-1-1");
build() {
Column() {
Button("DatePickerDialog")
.margin(20)
.onClick(() => {
this.getUIContext().showDatePickerDialog({
start: new Date("2000-1-1"),
end: new Date("2100-12-31"),
selected: this.selectedDate,
maskRect: {
x: 30,
y: 60,
width: '100%',
height: '60%'
},
onDateAccept: (value: Date) => {
// Use the setFullYear method to set the date when the OK button is touched. In this way, when the date picker dialog box is displayed again, the selected date is the date last confirmed.
this.selectedDate = value;
console.info("DatePickerDialog:onDateAccept()" + value.toString());
}
});
})
}.width('100%')
}
}
```
### Example 6: Setting the Background
This example demonstrates how to set the dialog box background using **backgroundColor**, **backgroundBlurStyle**, and **shadow**.
```ts
// xxx.ets
@Entry
@Component
struct DatePickerDialogExample {
selectedDate: Date = new Date("2010-1-1");
build() {
Column() {
Button("DatePickerDialog")
.margin(20)
.onClick(() => {
this.getUIContext().showDatePickerDialog({
start: new Date("2000-1-1"),
end: new Date("2100-12-31"),
selected: this.selectedDate,
backgroundColor: 'rgb(204, 226, 251)',
backgroundBlurStyle: BlurStyle.NONE,
shadow: ShadowStyle.OUTER_FLOATING_SM,
onDateAccept: (value: Date) => {
// Use the setFullYear method to set the date when the OK button is touched. In this way, when the date picker dialog box is displayed again, the selected date is the date last confirmed.
this.selectedDate = value;
console.info("DatePickerDialog:onDateAccept()" + value.toString());
}
});
})
}.width('100%')
}
}
```
### Example 7: Switching Between Gregorian and Lunar Calendars
This example demonstrates how to set the date picker dialog box to display either the Gregorian (solar) calendar or the lunar calendar using **lunar** and **lunarSwitch**.
```ts
// xxx.ets
@Entry
@Component
struct DatePickerDialogExample {
selectedDate: Date = new Date("2010-1-1");
build() {
Column() {
Button("DatePickerDialog")
.margin(20)
.onClick(() => {
this.getUIContext().showDatePickerDialog({
start: new Date("2000-1-1"),
end: new Date("2100-12-31"),
selected: this.selectedDate,
lunar: false,
onDateAccept: (value: Date) => {
// Use the setFullYear method to set the date when the OK button is touched. In this way, when the date picker dialog box is displayed again, the selected date is the date last confirmed.
this.selectedDate = value;
console.info("DatePickerDialog:onDateAccept()" + value.toString());
}
});
})
Button("Lunar DatePickerDialog")
.margin(20)
.onClick(() => {
this.getUIContext().showDatePickerDialog({
start: new Date("2000-1-1"),
end: new Date("2100-12-31"),
selected: this.selectedDate,
lunar: true,
lunarSwitch: true,
onDateAccept: (value: Date) => {
this.selectedDate = value;
console.info("DatePickerDialog:onDateAccept()" + value.toString());
}
});
})
}.width('100%')
}
}
```
### Example 8: Setting Display of Month and Day Columns
This example demonstrates how to configure the **mode** parameter to display only the month and day columns in the date picker dialog box.
```ts
// xxx.ets
@Entry
@Component
struct DatePickerDialogExample {
selectedDate: Date = new Date("2010-1-1");
build() {
Column() {
Button("DatePickerDialog")
.margin(20)
.onClick(() => {
this.getUIContext().showDatePickerDialog({
start: new Date("2000-1-1"),
end: new Date("2100-12-31"),
selected: this.selectedDate,
mode: DatePickerMode.MONTH_AND_DAY,
onDateAccept: (value: Date) => {
// Use the setFullYear method to set the date when the OK button is touched. In this way, when the date picker dialog box is displayed again, the selected date is the date last confirmed.
this.selectedDate = value;
console.info("DatePickerDialog:onDateAccept()" + value.toString());
}
});
})
}.width('100%')
}
}
```
### Example 9: Setting Cyclic Scrolling
This example demonstrates how to set whether to enable cyclic scrolling using **canLoop**.
```ts
// xxx.ets
@Entry
@Component
struct DatePickerDialogExample {
@State isLoop: boolean = true;
selectedDate: Date = new Date("2010-1-1");
build() {
Column() {
Button("DatePickerDialog")
.margin(20)
.onClick(() => {
this.getUIContext().showDatePickerDialog({
start: new Date("2000-1-1"),
end: new Date("2100-12-31"),
selected: this.selectedDate,
canLoop: this.isLoop,
onDateAccept: (value: Date) => {
// Use the setFullYear method to set the date when the OK button is touched. In this way, when the date picker dialog box is displayed again, the selected date is the date last confirmed.
this.selectedDate = value;
console.info("DatePickerDialog:onDateAccept()" + value.toString());
}
});
})
Row() {
Text('Cyclic scrolling').fontSize(20)
Toggle({ type: ToggleType.Switch, isOn: true })
.onChange((isOn: boolean) => {
this.isLoop = isOn;
})
}.position({ x: '60%', y: '40%' })
}.width('100%')
}
}
```
### Example 10: Customizing the Background Blur Effect
This example demonstrates how to customize the background blur effect by configuring [backgroundBlurStyleOptions](#datepickerdialogoptions). This functionality is supported since API version 19.
```ts
@Entry
@Component
struct DatePickerDialogExample {
selectedDate: Date = new Date("2010-1-1");
build() {
Stack({ alignContent: Alignment.Top }) {
Image($r('app.media.bg'))
Column() {
Button("DatePickerDialog")
.margin(20)
.onClick(() => {
this.getUIContext().showDatePickerDialog({
start: new Date("2000-1-1"),
end: new Date("2100-12-31"),
selected: this.selectedDate,
backgroundColor: undefined,
backgroundBlurStyle: BlurStyle.Thin,
backgroundBlurStyleOptions: {
colorMode: ThemeColorMode.LIGHT,
adaptiveColor: AdaptiveColor.AVERAGE,
scale: 1,
blurOptions: { grayscale: [20, 20] },
},
});
})
}.width('100%')
}
}
}
```
### Example 11: Customizing the Background Effect
This example demonstrates how to customize the background effect by configuring [backgroundEffect](#datepickerdialogoptions). This functionality is supported since API version 19.
```ts
@Entry
@Component
struct DatePickerDialogExample {
selectedDate: Date = new Date("2010-1-1");
build() {
Stack({ alignContent: Alignment.Top }) {
Image($r('app.media.bg'))
Column() {
Button("DatePickerDialog")
.margin(20)
.onClick(() => {
this.getUIContext().showDatePickerDialog({
start: new Date("2000-1-1"),
end: new Date("2100-12-31"),
selected: this.selectedDate,
backgroundColor: undefined,
backgroundBlurStyle: BlurStyle.Thin,
backgroundEffect: {
radius: 60,
saturation: 0,
brightness: 1,
color: Color.White,
blurOptions: { grayscale: [20, 20] }
},
});
})
}.width('100%')
}
}
}
```