ical4j DateTime解析异常

ical4j DateTime parse exception

使用 ical4j 1.0.6,我试图从 "DTSTART..." 字符串实例化 DateTime。即使对于 DateTime documentation and ical4j wiki

中列为有效的示例,构造函数也会抛出 ParserException
      String date = "DTSTART;TZID=US-Eastern:19970714T133000";
      try {
        DateTime dt = new DateTime(date);
      } catch (ParseException e) {
        e.printStackTrace(); //always thrown
      }

java.text.ParseException: Unparseable date: "DTSTART;TZID=US-Eastern:19970714T133000" (at offset 0)

我尝试将 KEY_RELAXED_PARSING 设置为 true,但无济于事。

我做错了什么?

查看 javadoc,构造函数 DateTime(String) 说:

Constructs a new DateTime instance from parsing the specified string representation in the default (local) timezone.

所以我猜字符串的 "DSTART" 和 "TZID" 部分太多了。

要设置特定时区,请阅读Working with timezones部分。

我最终使用了这段代码

      String[] parts = property.split(":");
      if (parts.length > 1) {
        try {
          String timezone = parts[0].replace("DTSTART;TZID=", "");

          DtStart start = new DtStart();
          start.getParameters().add(Value.DATE_TIME);
          start.getParameters().add(new TzId(timezone));
          start.setValue(parts[1]);
        } catch (ParseException e) {
          e.printStackTrace();
        }
      }