代码笔记
import java.util.*;
//Date类位于util包中
public class Date1 {
public static void main(String args[]){
Date date=new Date();
System.out.println(date);
/*使用Date类的无参数构造方法创建的对象可以获取本机的当前日期和时间
时间排列顺序:星期、月份、日、时钟秒、时区、年份
Date类内重写了toString方法,使得输出时不输出date存放的引用,而是输出对象实体的内容
*/
long l=System.currentTimeMillis();
System.out.println(l);
/*使用currentTimeMillis()方法可以获得当前时间距离公元时间的时间间隔
1970年1月1日0时是”公元“,该”公元“是“格林威治”时间
currentTimeMillis()方法是System类的静态方法
*/
Date date1=new Date(1000);
/*由于运行java程序的本地时区是“北京”时区,距离“格林威治”时间差为8小时。
Date类构造函数中的参数决定了Date对象的时间距离本地时间有多少。
若是正数则大于本地时间,若是负数则是小于本地时间
*/
Date date2=new Date(-1000);
System.out.println(date1+" "+date2);
}
}