【发布时间】:2018-04-27 08:22:49
【问题描述】:
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, YYYY, EEE", Locale.US);
System.out.println(sdf.format(new Date()));
System.out.println(sdf.format(sdf.parse("Apr 27, 2018, Fri")));
Java 未按预期解析日期并输出:
Apr 27, 2018, Fri
Jan 05, 2018, Fri // I can not understand why java parse the month of April as January
【问题讨论】:
-
我建议您避免使用
SimpleDateFormat类。它不仅与Date一起早已过时,而且还出了名的麻烦。今天我们在java.time, the modern Java date and time API 和它的DateTimeFormatter中做得更好。