DateTimeFormat giving diferent result than SimpleDateformat

Why is DateTimeFormatter giving a differnt result than SimpleDateFormat?

String dateString = "0819-03-03";

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

Date date = sdf.parse(dateString);

System.out.println(sdf.format(date));

System.out.println(DateTimeFormatter.ISO_LOCAL_DATE.format(ZonedDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault())));

The output is:

0819-03-03 // SimpleDateFormat

0819-03-07 // DateTimeFormatter

I suspect it has something to do with the date being very old....

Read More »

By: StackOverFlow - Monday, 19 November

Related Posts