1、Date型別轉換為String型別:SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");String str = sdf.format(date1);String str1 =sdf1.format(date1); System.out.println(str);System.out.println(str1); 說明:sdf和sdf1只是兩個不懂的格式化型別的定義,型別可以自由定義2、String與Timestamp型別轉換:1、String轉換為Timestamp型別:String str3 = "2011-02-02 12:12:12";Timestamp.valueOf(str3);System.out.println(Timestamp.valueOf(str3));
1、Date型別轉換為String型別:SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMdd");String str = sdf.format(date1);String str1 =sdf1.format(date1); System.out.println(str);System.out.println(str1); 說明:sdf和sdf1只是兩個不懂的格式化型別的定義,型別可以自由定義2、String與Timestamp型別轉換:1、String轉換為Timestamp型別:String str3 = "2011-02-02 12:12:12";Timestamp.valueOf(str3);System.out.println(Timestamp.valueOf(str3));