1. Description of false narrative
Exception in thread "main" Java.lang.IllegalArgumentException:Cannot format given Object as a dateat Java.text.DateFormat . Format (dateformat.java:301) at Java.text.Format.format (format.java:157) at Com.you.util.DateBefore.getMonthBefore (datebefore.java:24) at Com.you.util.DateBefore.main (datebefore.java:33)
2. Cause of error
/** * */package com.you.util;import java.text.simpledateformat;import java.util.calendar;/** * @author YouHaidong * */public class Datebefore {/** * * @return */public static string Getmonthbefore (String subStr) {Calendar calendar = Calendar.getinstance (); Calendar.add (Calendar.month,-12); SimpleDateFormat SDF = new SimpleDateFormat ("Yyyymm"); subStr = Sdf.format (calendar); return subStr;} /** * @param args */public static void main (string[] args) {String date = Getmonthbefore ("2014-02"); SYSTEM.OUT.PRINTLN (date);}}
Date format Conversion exception
3, the solution of the method
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
Exception in thread "main" java.lang.IllegalArgumentException