HarmonyOS 日历重复规则如何设置

使用ohos.calendarManager添加日历提醒,如何添加每周一、周三、周五的提醒?

HarmonyOS
2024-12-25 15:41:29
1013浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

开始时间startTime需为一三五,根据date.getTime()具体日期设置,endTime为结束时间,这里设置为了10s。

import { BusinessError } from '@kit.BasicServicesKit';
import { calendarManager } from '@kit.CalendarKit';
import { calendarMgr } from '../entryability/EntryAbility';
let calendar : calendarManager.Calendar | undefined = undefined;
const date = new Date();
const event: calendarManager.Event[] =[{
  title: 'MyEvent1',
  type: calendarManager.EventType.NORMAL,
  startTime: date.getTime()-24*60 * 60 * 1000,
  endTime: date.getTime()-24*60 * 60 * 1000+10000,
  recurrenceRule: {
    recurrenceFrequency:calendarManager.RecurrenceFrequency.WEEKLY,
    daysOfWeek:[1, 3, 5]
  }
},
]

@Entry
@Component
struct Index62 {
  @State message: string = 'Hello World';

  build() {
    RelativeContainer() {
      Text(this.message)
        .id('Index62HelloWorld')
        .fontSize(50)
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
        .onClick(()=>{
          calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => {
            if (err) {
              console.error(`Failed to get calendar, err -> ${JSON.stringify(err)}`);
            } else {
              console.info(`Succeeded to get calendar, data -> ${JSON.stringify(data)}`);
              calendar = data;
              await calendar.addEvents(event).then(()=>{

              }).catch((err: BusinessError) => {
                console.error(`Failed to filter by title, err -> ${JSON.stringify(err)}`);
              });
              const filter = calendarManager.EventFilter.filterByTitle('MyEvent');
              calendar.getEvents(filter).then((data: calendarManager.Event[]) => {
                console.info(`Succeeded to filter by title, data -> ${JSON.stringify(data)}`);
              }).catch((err: BusinessError) => {
                console.error(`Failed to filter by title, err -> ${JSON.stringify(err)}`);
              });
            }
          });
        })
    }
    .height('100%')
    .width('100%')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
分享
微博
QQ
微信
回复
2024-12-25 18:15:52
相关问题
HarmonyOS 如何实现日历周期性重复
575浏览 • 1回复 待解决
HarmonyOS 日历里面添加日历问题
803浏览 • 1回复 待解决
日历里面怎么设置周首日为周二呀
251浏览 • 0回复 待解决
HarmonyOS 如何限制TextInput的规则
1214浏览 • 1回复 待解决
PA开发,如何添加日历提醒?
4967浏览 • 1回复 待解决
HarmonyOS 如何跳转至系统的日历APP
824浏览 • 1回复 待解决
HarmonyOS 创建日历失败
825浏览 • 1回复 待解决
HarmonyOS 日历相关组件
1201浏览 • 1回复 待解决
HarmonyOS 集成日历SDK
823浏览 • 1回复 待解决
HarmonyOS 日历组件cjcalendar文档
1031浏览 • 1回复 待解决
长按事件如何重复触发
2784浏览 • 1回复 待解决
JS如何添加日历日程提醒?
8942浏览 • 1回复 待解决
HarmonyOS 包名规则
760浏览 • 1回复 待解决
HarmonyOS重复点击
488浏览 • 1回复 待解决
HarmonyOS日历组件吗?
1194浏览 • 1回复 待解决
HarmonyOS 日历相关的绘制
667浏览 • 1回复 待解决