1.Date类概述
类Date表示特定的瞬间,精确到毫秒
2.构造方法
public Date()
public Date(long date)
3.成员方法
public long getTime()
public void setTime(long time)
package com;
import java.util.Date;
/**
* Date类概述
* Date类表示特定的瞬间,精确到毫秒
*
* 构造方法
* public Date()
* public Date(long date)
*
* 成员方法
* public long getTime()
* public void setTime(long time)
*
*/
public class DateDemo {
public static void main(String[] args) {
//public Date()
Date date = new Date();
System.out.println(date);//Wed Oct 12 19:20:56 CST 2016
//public Date(long date)
long currentTime = System.currentTimeMillis();
Date date2 = new Date(currentTime);
System.out.println(date2);//Wed Oct 12 19:21:41 CST 2016
//public long getTime()
long time = date.getTime();
System.out.println(time);//1476271328357
//public void setTime(long time)
date.setTime(System.currentTimeMillis());
System.out.println(date);//Wed Oct 12 19:22:57 CST 2016
}
}
转载于:https://blog.51cto.com/11841428/1861234