使用ical4j 1.0.6,我试图从“DTSTART.”实例化一个DateTime。绳子。构造函数将抛出一个ParserException,即使对于DateTime文档和ical4j维基中列出的示例也是如此。
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,但没有效果。
我做错了什么?
发布于 2015-07-24 11:47:13
在javadoc中,构造函数DateTime(字符串)说:
通过解析默认(本地)时区DateTime中指定的字符串表示形式来构造新的实例。
因此,我认为字符串的"DSTART“和"TZID”部分太多了。
若要设置特定的TimeZone,请阅读使用时区部分。
发布于 2015-07-24 14:02:20
最后我使用了这段代码
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();
}
}https://stackoverflow.com/questions/31609186
复制相似问题