使用CalendarPickerDialog,DatePickerDialog,TimePickerDialog展示年月,月日或者年月日时分秒 HarmonyOS 鸿蒙Next

使用CalendarPickerDialog,DatePickerDialog,TimePickerDialog展示年月,月日或者年月日时分秒 HarmonyOS 鸿蒙Next cke_226.png

选择年时月处有其他内容无法遮蔽,也没有办法通过设置样式盖住


更多关于使用CalendarPickerDialog,DatePickerDialog,TimePickerDialog展示年月,月日或者年月日时分秒 HarmonyOS 鸿蒙Next的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于使用CalendarPickerDialog,DatePickerDialog,TimePickerDialog展示年月,月日或者年月日时分秒 HarmonyOS 鸿蒙Next的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在鸿蒙Next系统中,使用CalendarPickerDialogDatePickerDialogTimePickerDialog来展示年月、月日或年月日时分秒,可以通过以下方式实现:

  1. CalendarPickerDialog:用于选择日期,支持展示年月日。通过CalendarPickerDialog.Builder创建并设置日期范围、初始日期和选择日期的监听器。

  2. DatePickerDialog:用于选择日期,支持展示年月或月日。通过DatePickerDialog.Builder创建并设置日期格式、初始日期和选择日期的监听器。

  3. TimePickerDialog:用于选择时间,支持展示时分或时分秒。通过TimePickerDialog.Builder创建并设置时间格式、初始时间和选择时间的监听器。

示例代码片段:

// CalendarPickerDialog
let calendarPickerDialog = new CalendarPickerDialog.Builder()
    .setStartDate(new Date(2023, 0, 1))
    .setEndDate(new Date(2023, 11, 31))
    .setSelectedDate(new Date(2023, 9, 15))
    .onDateSelected((date) => {
        console.log("Selected date: " + date);
    })
    .build();
calendarPickerDialog.show();

// DatePickerDialog
let datePickerDialog = new DatePickerDialog.Builder()
    .setDatePickerMode(DatePickerMode.YEAR_MONTH)
    .setSelectedDate(new Date(2023, 9, 15))
    .onDateSelected((date) => {
        console.log("Selected date: " + date);
    })
    .build();
datePickerDialog.show();

// TimePickerDialog
let timePickerDialog = new TimePickerDialog.Builder()
    .setTimePickerMode(TimePickerMode.HOUR_MINUTE_SECOND)
    .setSelectedTime(new Date(2023, 9, 15, 12, 30, 45))
    .onTimeSelected((time) => {
        console.log("Selected time: " + time);
    })
    .build();
timePickerDialog.show();

以上代码展示了如何在鸿蒙Next系统中使用这些对话框组件来选择和展示日期时间信息。

回到顶部