我在使用收到这个异常的GregorianCalendar
I received this exception while using GregorianCalendar
java.lang.IllegalArgumentException异常:叛逆类:类java.util.GregorianCalendar中的
谁知道如何解决,
请帮我。
P / S:我用下面的code:
p/s : I used the following code :
Calendar someDate = GregorianCalendar.getInstance();
someDate.add(Calendar.DAY_OF_YEAR, -7);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = dateFormat.format(someDate);
更新时间:我应该使用此行实现了日期和时间:
UPDATED I should be use this line to achieve the date time :
字符串formattedDate = dateFormat.format(someDate.getTime());
一个日历不能直接格式化,您需要从日历得到的日期,就像这样:
A Calendar can't be directly formatted, you need to get the Date from the Calendar, like this:
String formattedDate = dateFormat.format(someDate.getTime());