package demo01; import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date; public class demo27 { public static void main ...
package demo01;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class demo27 {
public static void main(String[] args) throws ParseException{
//Data---->String
//創建日期對象
Date time = new Date();
//創建格式化對象
SimpleDateFormat data = new SimpleDateFormat("yyyy年MM月dd日HH:mm:ss");
String s = data.format(time);
System.out.println(s);
//String---->Data
String str = "2018-07-30 17:27:18";
//在把一個字元串解析為日期的時候,請註意格式必須和給定的字元串格式匹配
SimpleDateFormat data1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dd = data1.parse(str);
System.out.println(dd);
}
}