java.lang.IllegalArgumentException异常:坏类:类java.util.GregorianCalendar中的 [英] java.lang.IllegalArgumentException: Bad class: class java.util.GregorianCalendar

查看:2747
本文介绍了java.lang.IllegalArgumentException异常:坏类:类java.util.GregorianCalendar中的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用收到这个异常的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());

这篇关于java.lang.IllegalArgumentException异常:坏类:类java.util.GregorianCalendar中的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆