在Outlook或Thunderbird中导入时,Java,ICS日历格式未显示时间 [英] Java, ICS calendar format not showing time when imported in Outlook or Thunderbird

查看:235
本文介绍了在Outlook或Thunderbird中导入时,Java,ICS日历格式未显示时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个Java项目中创建ICS文件,但日期和时间有问题.每当我导入ICS文件时,我都希望在ICS文件中显示事件的开始时间和事件的结束时间.

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.

我尝试使用也包含endTime的构造函数,没有运气,仍然显示00:00.我用来生成ICS文件的以下代码,下面是ICS文件的内容.

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.

代码:

 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文件的样子:

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

现在,当我导入此文件时,Outlook,雷鸟或Evolution中没有提到任何时间.我究竟做错了什么?谢谢你.

Now when I import this, no time is mentioned in Outlook, thunderbird or Evolution. What am I doing wrong? Thank you.

推荐答案

您只为VEVENTDTSTARTDTEND属性指定了DATE而不是DATE-TIME.

you are only specifying a DATE and not a DATE-TIME for the DTSTART and DTEND properties of your VEVENT.

注意:这些是日期时间开始"和日期时间结束"的缩写.

Note: those are short for Date-Time Start and Date-Time End).

有关更多详细信息,您可以参考RFC5545,尤其是日期时间 DTSTART

for more details you can refer to RFC5545 and specifically DATE-TIME, or DTSTART, and VEVENT.

第二个也会提醒您DTSTART的默认设置是使用DATE-TIME格式,而不是DATE格式.

The second one, also will remind you that the default for DTSTART is to use DATE-TIME format and not DATE format.

第三个表示仅DATE值的DTSTART的用法

The third one indicates usage for DTSTART with only DATE value

"VEVENT"也是用于指定 日历中的周年纪念日或每日提醒.这些事件 具有"DTSTART"属性的DATE值类型,而不是 默认值类型为DATE-TIME.

The "VEVENT" is also the calendar component used to specify an anniversary or daily reminder within a calendar. These events have a DATE value type for the "DTSTART" property instead of the default value type of DATE-TIME.

这篇关于在Outlook或Thunderbird中导入时,Java,ICS日历格式未显示时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆