问题描述
用 SimpleDateFormat formatter = new SimpleDateFormat(); formatter.parse(strDate);是不可行的.. 问题补充:redstarofsleep 写道
解决方案
String d_str = "Tue May 17 10:26:26 CST 2011"; SimpleDateFormat formatter = new SimpleDateFormat("EEEE MMM dd HH:mm:ss Z yyyy"); d = formatter.parse(d_str); System.out.println(d.toString()); formatter = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss"); System.out.println(formatter.format(d));
解决方案二:
String str = "Tue May 17 10:26:26 CST 2011"; SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy",Locale.US); Date d = formatter.parse(str); System.out.println(d.toString());
解决方案三:
Calendar date = new GregorianCalendar(2011,1,1);SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); formatter.format(date.getTime());
解决方案四:
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");formatter.format(new Date());