3,public Date parse(String source):将String对象解析为Date对象。
示例代码:
//将Date对象格式化String对象。 public class Test01 { public static void main(String[] args) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str = dateFormat.format(new Date());
System.out.println(str);
}
}
//将String对象解析为Date对象。 public class Test02 { public static void main(String[] args) throws Exception{
DateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
Date date = dateFormat.parse("2018年08月30日 8:12:12");
System.out.println(date);
}
}