java ews appointment_ews-java-api学习:新建Recurring Appointment

/**

* Meeting:创建重复约会

*/

private void createRecurringAppointment(String userName, String password, String domain, String subject, String location, String startsTime, String endsTime, String recurrenceType, String recurrenceEndsDate, String body, boolean isAllDay) {

EWS ews = new EWS();

ExchangeService service = ews.connectEWS(userName, password, domain);

try {

Appointment appointment = new Appointment(service);

// 中国标准时间

TimeZoneDefinition tz = getTimeZoneDefinition(service, TIME_ZONE_CTT);

appointment.setSubject(subject); // 约会标题

appointment.setLocation(location); // 约会地点

appointment.setBody(MessageBody.getMessageBodyFromText(body)); // 约会正文

// 约会开始时间和结束时间

HashMap times = getStartsAndEndsTime(startsTime, endsTime);

appointment.setStart((Date) times.get("startsTime"));

appointment.setStartTimeZone(tz);

appointment.setEnd((Date) times.get("endsTime"));

appointment.setEndTimeZone(tz);

// 约会循环类型

Date dateRecurrenceStarts = appointment.getStart();

Date dateRecurrenceEnds = getRecurrenceEndsDate(recurrenceEndsDate);

Recurrence recurrences = null;

switch(recurrenceType.toLowerCase()) {

case "daily":

recurrences = new Recurrence.DailyPattern(dateRecurrenceStarts, 1); // 默认interval为1天

break;

case "weekly":

/**

* @param 重复会议开始日期

* @param 重复间隔为一周一次

* @param 重复会议发生在每周星期一

*/

recurrences = new Recurrence.WeeklyPattern(dateRecurrenceStarts, 1, DayOfTheWeek.Monday); // 默认每周一

break;

case "monthly":

/**

* @param 重复会议开始日期

* @param 重复间隔为一月一次

* @param 重复会议发生在每月一号

*/

recurrences = new Recurrence.MonthlyPattern(dateRecurrenceStarts, 1, 1); // 默认每月一号

break;

case "yearly":

/**

* @param 重复会议开始日期

* @param 重复间隔为一年一次

* @param 重复会议发生在每年六月一号

*/

recurrences = new Recurrence.YearlyPattern(dateRecurrenceStarts, Month.June, 1); // 默认每年六月一号

break;

default:

System.out.println("输入无效!");

break;

}

appointment.setRecurrence(recurrences);

appointment.getRecurrence().setStartDate(dateRecurrenceStarts);

appointment.getRecurrence().setEndDate(dateRecurrenceEnds);

appointment.setIsAllDayEvent(isAllDay); // 是否全天事件

appointment.save(WellKnownFolderName.Calendar, SendInvitationsMode.SendToNone);

} catch (Exception e) {

System.out.println("Error: Fail to create appointment!");

e.printStackTrace();

}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值