Number.comjava.text.DateFormatjava.text.ParseExceptionjava.text.SimpleDateFormatjava.util.DateTestSimpleDateFormat {
(String[] args) ParseException {
SimpleDateFormat df=SimpleDateFormat()Date d1=df.parse()System..println(df)Date d2=Date()String str=df.format(d2)System..println(str)DateFormat df2=SimpleDateFormat()System..println(df2.format(d1))}
}
为什么会在Date类转为字符串时 Date d2=new Date("1000L*3600*23")这一行报错 报非法参数异常IllegalArgumentException 我查找了一下是因为Date类不能转为字符串对象了 需要转为long对象才能转为字符串对象
java.text.SimpleDateFormat@e863f5a0
Exception in thread "main" java.lang.IllegalArgumentException
at java.util.Date.parse(Date.java:617)
at java.util.Date.<init>(Date.java:274)
at Number.com.TestSimpleDateFormat.main(TestSimpleDateFormat.java:21)