Timestamp和Date的區別
時間戳Timestamp是date的一個瘦包裝器 //Timestamp貌似現在沒怎麼用了
import java.sql.Timestamp;
import java.util.Date;
public class DateTest {
public static void main(String[] args){
//表示 1970 年 1 月 1 日 00:00:00 以來的標準毫秒數
long today = System.currentTimeMillis();
Timestamp timestamp = new Timestamp(today);
System.out.println(today+":"+timestamp.getTime()+":"+timestamp.getDate());
// Date 的使用
Date date = new Date();
System.out.println(date.getDate()+":"+date.toString()+":"+date.getTime());
//相互轉化
Date date1 = new Date(timestamp.getTime());
Timestamp timestamp1 = new Timestamp(date.getTime());
System.out.println("時間:"+date1.getDate()+":"+timestamp1.getDate());
// JDK 1.1以後,使用 Calendar 和 DateFormat 來格式化
//詳細 見 Calendar和Data trunc和to_date 的用法
//
}
}