我正在开发一个 Java 项目,在该项目中我正在创建一个 ICS 文件,但日期和时间有问题。每当我导入 ICS 文件时,我想在 ICS 文件中显示事件的开始时间和事件的结束时间。
我尝试使用包含 endTime 的构造函数,但运气不好,仍然显示 00:00。下面的代码我用来生成 ICS 文件,下面是 ICS 文件的内容。
代码 :
Calendar icsCalendar = new Calendar();
icsCalendar.getProperties().add(Version.VERSION_2_0);
icsCalendar.getProperties().add(CalScale.GREGORIAN);
String startDateString = new SimpleDateFormat("yyyyMMdd'T'hhmmss'Z'").format(groupNotes.getStartTimestamp());
String endDateString = new SimpleDateFormat("yyyyMMdd'T'hhmmss'Z'").format(groupNotes.getEndTimestamp());
net.fortuna.ical4j.model.Date startDt = null;
net.fortuna.ical4j.model.Date endDateFortuna = null;
try {
startDt = new net.fortuna.ical4j.model.Date(startDateString, "yyyyMMdd'T'hhmmss'Z'");
endDateFortuna = new net.fortuna.ical4j.model.Date(endDateString, "yyyyMMdd'T'hhmmss'Z'");
} catch (ParseException e) {
e.printStackTrace();
}
java.util.Calendar endDate = java.util.Calendar.getInstance();
endDate.setTimeInMillis(groupNotes.getEndTimestamp().getTime());
/* long difference = groupNotes.getEndTimestamp().getTime() - groupNotes.getStartTimestamp().getTime();
int min = (int) (difference / (1000 * 60));
Dur dur = new Dur(0, 0, min, 0);*/
VEvent vEvent = new VEvent(startDt, endDateFortuna, groupNotes.getMnotetag());
vEvent.getProperties().add(new Description());
try {
vEvent.getProperties().getProperty(Property.DESCRIPTION).setValue(groupNotes.getMnotetext());
vEvent.getProperties().add(new Organizer("MAILTO:" + groupNotes.getNoteCreatorEmail()));
} catch (IOException | URISyntaxException | ParseException e) {
e.printStackTrace();
}
icsCalendar.getComponents().add(vEvent);
FileOutputStream fout = null;
try {
fout = new FileOutputStream(calFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
CalendarOutputter outputter = new CalendarOutputter();
outputter.setValidating(false);
try {
outputter.output(icsCalendar, fout);
return new FileInputStream("mycalendar.ics");
} catch (IOException | ValidationException e) {
e.printStackTrace();
}
}
这是我的 ICS 文件的样子:
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:20150910T152828Z
DTSTART;VALUE=DATE:20150911
DTEND;VALUE=DATE:20150911
SUMMARY:
DESCRIPTION:poip
ORGANIZER:MAILTO:email@gmail.com
END:VEVENT
END:VCALENDAR
现在,当我导入它时,Outlook、Thunderbird 或 Evolution 中没有提到时间。我究竟做错了什么?谢谢你。