我想使用SimpleDateFormat.parse
方法来设置日期:
private static SimpleDateFormat fmt = new SimpleDateFormat("dd-MMM");
...
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
calendar.setTime(fmt.parse("9-Jul"));
calendar.set(Calendar.YEAR, year);
但我得到:
Exception in thread "main" java.text.ParseException: Unparseable date: "9-Jul"
at java.text.DateFormat.parse(Unknown Source)
at BusinessPlan.main(BusinessPlan.java:116)
代码来自 Apache 示例站点,发布号为 this bug .
最佳答案
对我来说效果很好
尝试设置区域设置
SimpleDateFormat fmt = new SimpleDateFormat("dd-MMM", Locale.US);
关于java - SimpleDateFormat 无法解析的日期 : "9-Jul" when using parse method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22266576/