java对字符串按一定格式转换成日期Date型
见下代码,很好理解。
*/
public static void main(String[] args) throws ParseException {
// TODO Auto-generated method stub
String format = "yyyyMMdd";
String format2 = "yyyy-MM-dd";
DateFormat t = new SimpleDateFormat(format);
DateFormat t2 = new SimpleDateFormat(format2);
// String ty = t.format(new Date());
Date tt = t.parse("20090202");
Date tt2 = t2.parse("2009-02-02");
System.out.println(tt);
System.out.println(tt2);
}