我想使用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示例站点,并随此bug一起发布。
对我来说很好
尝试设置 Locale
SimpleDateFormat fmt = new SimpleDateFormat("dd-MMM", Locale.US);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句