I am having troubles parsing the following date 2020-06-11T09:03:46.000-0300
. As far i know, i should use pattern 'Z' to represent the '-0300' Zone offset, but this pattern does not produce the expected output. The code i am using to make the parse is
@Test
public void testDate(){
// The String and the pattern
String strFecha = "2020-06-11T09:03:46.000-0300";
String formato = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
// Create Formatter
DateTimeFormatter dtf = new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.appendPattern(formato)
.toFormatter()
.withZone(ZoneId.systemDefault());
// parse the String to ZonedDateTime
TemporalAccessor accessor = dtf.parse(strFecha, new ParsePosition(0));
ZonedDateTime fecha = ZonedDateTime.from(accessor);
LocalDateTime fechaOff = LocalDateTime.ofInstant(fecha.toInstant(), ZoneId.systemDefault());
// print
System.out.println("str: " + strFecha + ", " + fecha + ", fecha: " + fechaOff);
}
The problem is, my code does not produces my expected output, which is 2020-06-11T07:03:46-05:00
(3 hours less), instead, the code returns the original date 2020-06-11T09:03:46.000-05:00
it does not make any change in time (Still 9am). I can't figure the mistake in my code. any help would be apreciate