我正在使用iCalender API以JAVA发送会议请求。目前,它在IST时区运行良好,但在CST/CDT或任何其他时区部署了相同的应用程序,当生成会议请求时,它在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:VCALENDARn" +
"METHOD:REQUESTn" +
"PRODID: BCP - Meetingn" +
"VERSION:2.0n" +
"BEGIN:VEVENTn" +
"DTSTAMP:" + iCalendarDateFormat.format(startDate) + "n" +
"DTSTART:" + iCalendarDateFormat.format(startDate)+ "n" +
"DTEND:" + iCalendarDateFormat.format(endDate)+ "n" +
"SUMMARY:Created New Taskn" +
"UID:" + taskDTO.getTaskID() + "n" +
"ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:MAILTO:"+taskDTO.getLoggedInUserEmailID()+"n" +
"ORGANIZER:MAILTO:"+taskDTO.getLoggedInUserEmailID()+"n" +
"SEQUENCE:0n" +
"PRIORITY:5n" +
"CLASS:PUBLICn" +
"STATUS:CONFIRMEDn" +
"TRANSP:OPAQUEn" +
"BEGIN:VALARMn" +
"ACTION:DISPLAYn" +
"DESCRIPTION:REMINDERn" +
"TRIGGER;RELATED=START:-PT00H15M00Sn" +
"END:VALARMn" +
"END:VEVENTn" +
"END:VCALENDAR";
calendarPart.addHeader("Content-Class", "urn:content-classes:calendarmessage");
calendarPart.setContent(calendarContent, "text/calendar;method=CANCEL");
return calendarPart;
}
如果你在同一上有任何输入,请告诉我
提前感谢!!!
好吧,这完全取决于您如何格式化日期和时间。示例代码没有显示如何定义iCalendarDateFormat变量。我怀疑这是类似于";yyyyMMdd"HHmms'Z'";其指示具有UTC时间的日期(位于https://www.rfc-editor.org/rfc/rfc5545#section-3.3.5)。因此,您的上午10点IST将转换为UTC时间的凌晨4点半,收到后,将转换为接收客户的当地时间。
如果你真的想说";无论用户/客户端可能在哪里,该事件都应该在上午10点出现";,您应该使用带有当地时间的日期(表格#1https://www.rfc-editor.org/rfc/rfc5545#section-3.3.5)。换句话说,您的iCalendarDateFormat不应包含最终的"Z"。
最后,一个简单的拼写错误:您正在发送iMIP REQUEST,但您将calendarPart Content Type设置为"文本/日历;method=CANCEL"。有些客户可能不喜欢这样。