Error converting date with two digits for the Year field
问题 // input format: dd/MM/yy SimpleDateFormat parser = new SimpleDateFormat("dd/MM/yy"); // output format: yyyy-MM-dd SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); System.out.println(formatter.format(parser.parse("12/1/20"))); // 0020-11-01 I am using the above code but it is giving me year as '0020' instead of '2020'. 回答1: Use java.time for this: public static void main(String[] args) { String dateString = "12/1/20"; LocalDate localDate = LocalDate.parse(dateString,