一、概述
Data类表示特定的瞬间,精确到毫秒,它是java.util包下的类,用之前需要先导包
二、构造方法
- public Date():根据当前系统时间,获取其对应的Data对象
- public Date(long date):根据给定的整数,获取其对应的Date对象
三、成员方法
- public long getTime():获取毫秒值
- public void setTime(long time):设置时间,单位是毫秒值
四、实例
public class Test{
public static void main(String[] args) {
// 空参构造
Date d1 = new Date();
// 传参构造
Date d2 = new Date(12312321);
System.out.println(d1);
System.out.println(d2);
// 获取毫秒值
System.out.println(d1.getTime());
// 设置毫秒值
d1.setTime(1111111);
System.out.println(d1);
}
}