Date类
Date类
Date表示特定的瞬间,精确到毫秒。Date类中的大部分方法都已经被Calendar类中的方法所取代。
时间单位:
1秒=1000毫秒
1毫秒=1000微秒
1微秒=1000纳秒
public static void main(String[] args) {
Date date = new Date();
System.out.println(date.getTime());//gettime()方法获取当前时间的毫秒数(从1970年1月1日开始)
System.out.println(date);
Date date2=new Date(date.getTime()-(60*60*24*1000));//用当前时间的毫秒数减去一天的毫秒数,得到昨天此时的时间
boolean b=date2.before(date); //before()方法用于判断时间的前后
System.out.println(b);
}
本文来自博客园,作者:望穿先生,转载请注明原文链接:https://www.cnblogs.com/wangchuanxiansheng/p/15839484.html