我想将 Tue Jun 01 00:00:00 IST 112
转换为 01-JUN-2012
我用过
Calendar calendar = new GregorianCalendar(year, 6, Calendar.DAY_OF_MONTH);
Date maxDate=new Date();
maxDate=calendar.getTime();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
SimpleDateFormat s=new SimpleDateFormat("dd-mmm-yyyy");
s.format(maxDate);
但我得到30-000-0112
最佳答案
使用大写 M 表示月份,
SimpleDateFormat s=new SimpleDateFormat("dd-MMM-yyyy");
此外,您首先设置日期,然后重置日历,我想这不是您想要做的,所以您可能需要将其更改为如下
Date maxDate=new Date();
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
maxDate=calendar.getTime();
SimpleDateFormat s=new SimpleDateFormat("dd-MMM-yyyy");
s.format(maxDate);
查看
关于java - SimpleDateFormat 结果不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11356109/