Timestamp_时间戳

时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。

package timestamp;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

import freemarker.template.SimpleDate;

public class Test_timestamp {

  /**
  * @param args
  */
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String str = sdf.format(new Date().getTime()).toString();
    System.out.println(str+"-------------1");

    Timestamp ts = new Timestamp(System.currentTimeMillis());
    //String->Timestamp
    System.out.println(ts.valueOf(str)+"-------------2");

    //Timestamp->String
    System.out.println(sdf.format(ts).toString()+"-------------3");

    //Timestamp->Date
    Date date = new Date() ;
    date = ts;
    System.out.println(date+"-------------4");

    //Date->Timestamp
    //父类 子类
    Timestamp ts1 = new Timestamp(new Date().getTime());
    System.out.println(ts1);
  }

}

   

原文地址:https://www.cnblogs.com/0914lx/p/6984837.html