I am working on a Java project in which I am creating an ICS file and there is something wrong with date and time. Whenever I import the ICS file, I want to show the startTime of event and endTime of Event in the ICS file.
I tried using the constructor which contains endTime as well, no luck, still shows 00:00. The below code I am using to generate an ICS file and below that is the content of the ICS file.
Code :
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();
}
}
Here is how my ICS file looks like :
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
Now when I import this, no time is mentioned in Outlook, thunderbird or Evolution. What am I doing wrong? Thank you.