`

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
  
 }
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics