我最近搬到Java 8,希望更容易处理本地和分区时间.
但是,在我看来,在解析一个简单的日期时,我面临一个简单的问题.
public static ZonedDateTime convertirAFecha(String fecha) throws Exception {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(
ConstantesFechas.FORMATO_DIA).withZone(
obtenerZonaHorariaServidor());
ZonedDateTime resultado = ZonedDateTime.parse(fecha, formatter);
return resultado;
}
Run Code Online (Sandbox Code Playgroud)
就我而言:
所以,这是一个简单的例子.但是,解析会抛出此异常:
java.time.format.DateTimeParseException: Text '15/06/2014' could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: {},ISO resolved to 2014-06-15 of type java.time.format.Parsed
Run Code Online (Sandbox Code Playgroud)
有小费吗?我一直在尝试解析和使用TemporalAccesor的不同组合,但到目前为止没有任何运气.
最好的祝福