我正在尝试将ISO 8601时间转换为可读的本地时区Android设备的格式。
String date = "2016-09-24T06:24:01Z";
LocalDate test = LocalDate.parse(date, ISO_INSTANT);
但是它返回了:
从阅读http://www.threeten.org/threetenbp/apidocs/org/threeten/bp/format/DateTimeFormatter.html#ISO_INSTANT来看,我正在做的事情似乎是可能的。方法抛出'org.threeten.bp.format.DateTimeParseException'异常
我做错了什么?
编辑
扩展异常错误:无法从TemporalAccessor获取LocalDate:DateTimeBuilder[fields={MilliOfSecond=0, NanoOfSecond=0, InstantSeconds=1474698241, MicroOfSecond=0}, ISO, null, null, null],类型为org.threeten.bp.format.DateTimeBuilder
编辑2
解决方案在下面的答案中。对于任何遇到这个问题的人,如果您想指定自定义输出格式,则可以使用:String format = "MMMM dd, yyyy \'at\' HH:mm a";
String dateString = DateTimeFormatter.ofPattern(format).withZone(ZoneId.systemDefault()).format(instant);