使用DateFormat的使用,然后自己试了下,结果出来个错误:
java.text.ParseException: Unparseable date: "11/10/10"
at java.text.DateFormat.parse(DateFormat.java:337)
下面是Date的输出比较:
Date date = new Date();
System.out.println(date.toString());//Wed Nov 10 10:15:05 CST 2010
DateFormat df = new SimpleDateFormat ("yyyy-MM-dd");
Date d1 = df.parse("2001-01-01");
System.out.println(d1.toString());//Mon Jan 01 00:00:00 CST 2001
DateFormat df2 = DateFormat.getDateInstance(DateFormat.SHORT);
System.out.println(df2.format(new Date())); // 11/10/10 中文系统下:10-11-10
Date d2 = df2.parse("11/10/10");
System.out.println("DateFormat.SHORT: " + d2.toString());//DateFormat.SHORT: Wed Nov 10 00:00:00 CST 2010
DateFormat df3 = DateFormat.getDateInstance(DateFormat.MEDIUM);
System.out.println(df3.format(new Date())); //Nov 10, 2010 中文系统下:2010-11-10
Date d3 = df3.parse("Nov 10, 2010");
System.out.println("DateFormat.MEDIUM: " + d3.toString());//DateFormat.MEDIUM: Wed Nov 10 00:00:00 CST 2010
DateFormat df4 = DateFormat.getDateInstance(DateFormat.LONG);
System.out.println(df4.format(new Date())); //November 10, 2010 中文系统下:2010年11月10日
Date d4 = df4.parse("November 10, 2010");
System.out.println("DateFormat.LONG: " + d4.toString());//DateFormat.LONG: Wed Nov 10 00:00:00 CST 2010
标签:10,00,java,DateFormat,text,System,Date,2010 From: https://blog.51cto.com/u_16070335/6189399