当前位置: 代码迷 >> Web前端 >> Timestamp跟Date的区别
  详细解决方案

Timestamp跟Date的区别

热度:287   发布时间:2012-08-27 21:21:57.0
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 的用法
??// http://cuityang.iteye.com/admin/blogs/1180024
??
?}
}

  相关解决方案