我正在使用 iCalender API 在 JAVA 中发送会议请求。目前它在 IST 时区工作正常,但相同的应用程序部署在 CST/CDT 或任何其他时区,它在生成会议请求时在 Outlook 中显示错误的时间。
例如,我正在生成今天的 Outlook 请求,开始时间为上午 10 点,结束时间为上午 11 点。发送 Outlook 请求时,它分别显示上午 11.30 下午 12.30 作为开始时间和结束时间。
请参阅下面是我如何设置请求的日历内容的代码。
private BodyPart buildCalendarPart() throws Exception {
BodyPart calendarPart = new MimeBodyPart();
TimeZone timezone = TimeZone.getDefault();
long offset = timezone.getOffset(Calendar.ZONE_OFFSET);
Calendar startTime = Calendar.getInstance();
startTime.setTime(taskDTO.getStartDate());
startTime.set(Calendar.HOUR_OF_DAY, 0);
startTime.set(Calendar.MINUTE, 0);
startTime.set(Calendar.SECOND, 0);
if(taskDTO.getStartTimeHrs().equals(12)) {
startTime.set(Calendar.HOUR, 0);
} else {
startTime.set(Calendar.HOUR, taskDTO.getStartTimeHrs());
}
startTime.set(Calendar.MINUTE, taskDTO.getStartTimeMins());
startTime.set(Calendar.SECOND, 0);
if(taskDTO.getStartTimeampm().equalsIgnoreCase(ApplicationConstant.AM))
startTime.set(Calendar.AM_PM,Calendar.AM);
else
startTime.set(Calendar.AM_PM,Calendar.PM);
System.out.println("Start Date :"+startTime.getTime().toString());
Calendar endTime = Calendar.getInstance();
endTime.setTime(taskDTO.getDueDate());
endTime.set(Calendar.HOUR_OF_DAY, 0);
endTime.set(Calendar.MINUTE, 0);
endTime.set(Calendar.SECOND, 0);
if(taskDTO.getEndTimeHrs().equals(12)){
endTime.set(Calendar.HOUR, 0);
}else{
endTime.set(Calendar.HOUR, taskDTO.getEndTimeHrs());
}
endTime.set(Calendar.MINUTE, taskDTO.getEndTimeMins());
endTime.set(Calendar.SECOND, 0);
if(taskDTO.getEndTimeampm().equalsIgnoreCase(ApplicationConstant.AM))
endTime.set(Calendar.AM_PM, Calendar.AM);
else
endTime.set(Calendar.AM_PM, Calendar.PM);
Date startDate = startTime.getTime();
Date endDate = endTime.getTime();
iCalendarDateFormat.setTimeZone(timezone);
//check the icalendar spec in order to build a more complicated meeting request
String calendarContent =
"BEGIN:VCALENDAR\n" +
"METHOD:REQUEST\n" +
"PRODID: BCP - Meeting\n" +
"VERSION:2.0\n" +
"BEGIN:VEVENT\n" +
"DTSTAMP:" + iCalendarDateFormat.format(startDate) + "\n" +
"DTSTART:" + iCalendarDateFormat.format(startDate)+ "\n" +
"DTEND:" + iCalendarDateFormat.format(endDate)+ "\n" +
"SUMMARY:Created New Task\n" +
"UID:" + taskDTO.getTaskID() + "\n" +
"ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:MAILTO:"+taskDTO.getLoggedInUserEmailID()+"\n" +
"ORGANIZER:MAILTO:"+taskDTO.getLoggedInUserEmailID()+"\n" +
"SEQUENCE:0\n" +
"PRIORITY:5\n" +
"CLASS:PUBLIC\n" +
"STATUS:CONFIRMED\n" +
"TRANSP:OPAQUE\n" +
"BEGIN:VALARM\n" +
"ACTION:DISPLAY\n" +
"DESCRIPTION:REMINDER\n" +
"TRIGGER;RELATED=START:-PT00H15M00S\n" +
"END:VALARM\n" +
"END:VEVENT\n" +
"END:VCALENDAR";
calendarPart.addHeader("Content-Class", "urn:content-classes:calendarmessage");
calendarPart.setContent(calendarContent, "text/calendar;method=CANCEL");
return calendarPart;
}
如果您对此有任何意见,请告诉我
提前致谢 !!!