我正在使用iCalender API在JAVA中发送会议请求,目前在IST时区运行良好,但在CSTCDT或其他时区部署相同的应用程序时,在Outlook中生成会议请求时显示错误的时间。目前它在IST时区工作正常,但在CSTCDT或其他时区部署相同的应用程序时,当会议请求生成时,在Outlook中显示错误的时间。
例如,我正在生成今天的Outlook请求,开始时间为10am,结束时间为11am。当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;
}
如果你有任何意见,请让我知道相同的。
先谢谢你 !!!
嗯,这取决于你如何格式化你的日期和时间。你的示例代码没有显示你如何定义iCalendarDateFormat变量。我怀疑它是类似于 "yyyMMdd'T'HHmmss'Z'"的东西,它表示一个UTC时间的日期(表格#2在 http:/tools.ietf.orghtmlrfc5545#section-3.3.5)。). 所以,您的10am IST将转换为UTC时间的4.5am,并且,当接收时,将被转换为接收客户端的本地时间。
如果你真的想说 "这个事件应该在上午10点出现,不管我们的客户端在哪里",你应该使用一个带有当地时间的日期(表格#1在 http:/tools.ietf.orghtmlrfc5545#section-3.3.5)。). 换句话说,你的iCalendarDateFormat不应该包括最后的'Z'。
最后,一个简单的排版错误:你发送了一个iMIP REQUEST,但你把 calendarPart Content-Type 设置为 "textcalendar;method=CANCEL". 有些客户可能不喜欢这样。