Caused by: java.lang.IllegalArgumentException: Bad class: class java.lang.String

筅森魡賤 提交于 2019-12-05 12:56:51

You could you this format for date formating.......

DateFormat inputFormatter1 = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = inputFormatter1.parse("2015-2-22");

DateFormat outputFormatter1 = new SimpleDateFormat("dd-MMM-yyyy");
String output1 = outputFormatter1.format(date1); // 

// if in this format input is 2015-2-22 than out put will be 22-Feb-2015

DateFormat.format expects Number or Date but you are passing it a String. You may want to parse the string but formatting it would just produce the same string you would parse.

You should format input and then passed to output format

try {
    String formattedString = new SimpleDateFormat("dd MMM yyyy").format(new SimpleDateFormat("yyyy-MM-dd").parse("2014-07-31"));
} catch (ParseException e) {
    e.printStackTrace();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!