首页 > 解决方案 > ThreeTenABP: DateTimeParseException

问题描述

尝试更改字符串的日期格式但得到 DateTimeException:

String oldDate = "2018-12-18T17:04:56+00:00";
String outputFormat = "DD-MM";
try {
    Instant instant = Instant.parse(oldDate);
    LocalDateTime localDateTime = instant.atZone(ZoneId.systemDefault()).toLocalDateTime();
    return localDateTime.format(DateTimeFormatter.ofPattern(outputFormat);
} catch (DateTimeException | IllegalArgumentException e) {
    Log.e("Error", e.getLocalizedMessage());
    return "";
}

我得到的错误是: 无法在索引 19 处解析文本“2018-12-18T17:04:56+00:00”

我正在使用 com.jakewharton.threetenabp:threetenabp:1.1.1 因为我不能使用 Java 8 类

标签: androiddatedatetimethreetenbp

解决方案



推荐阅读