java unix时间与正常时间互相转换

来源:互联网 发布:嗨皮网络 编辑:程序博客网 时间:2024/04/29 20:13

public static void main(String[] args) {
  SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd" );
  

  String time="1997-09-06";//注:改正后这里前后也加了空格
  Date date=new Date();
  try {
   date = format.parse(time);
  } catch (ParseException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  

  System.out.println("Format To times:"+date.getTime());
  
  Timestamp unixTime =   new Timestamp(date.getTime());
  //Timestamp unixTime =   new Timestamp();
  System.out.println(unixTime);

 }

原创粉丝点击