public class DateTest {
public static void main(String[] args) throws ParseException {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS");
String date1 = sdf.format(date);//通過SimpleDateFormat把date類型轉換為String類型
System.out.println(date1);
String date2 = "2016-11-01 13:10:12";
Date d2 = sdf.parse(date2);//把String轉換為date
System.out.println(d2);
System.out.println(date.compareTo(d2));//比較兩個時間
}
}