Date

Date表示特定的瞬間,精確到毫秒。Date類中的大部分方法都已經(jīng)被Calendar類中的方法所取代。

時間單位:

1秒=1000毫秒;

1毫秒=1000微秒;

1微秒=1000納秒;

未過時的方法:

1.方法after before

2.比較 compareTo();

3.比較是否相等 equals

源碼: public class Demo01 {
public static void main(String[] args) {
//1.創(chuàng)建Date對象
//今天時間
Date date1=new Date();
System.out.println(date1.toString());
System.out.println(date1.toLocaleString());
//計算昨天的時間
//
Date date2=new Date(date1.getTime()-60100060*24 );
System.out.println(date2.toLocaleString());

        //2.方法after before
        boolean b1=date1.after(date2);
        System.out.println(b1);
       boolean b2= date1.before(date2);
        System.out.println(b2);

        //比較 compareTo();
        int d=date1.compareTo(date2);
        System.out.println(d);
        int d1=date1.compareTo(date2);
        System.out.println(d1);
        int d2=date2.compareTo(date2);
        System.out.println(d2);

        //比較是否相等 equals
        boolean b3=date1.equals(date2);
        System.out.println(b3);
    }
}