天天看點

JDK1.5中的類庫---時間類Date

JDK1.5中的類庫---時間類Date

import java.util.Date;

import javax.swing.JOptionPane;

public class DateTest {

    public static void main(String args[]) {

        Date date1 = new Date();

        Date date2 = new Date();

        Date longdate = new Date(0L);

        String output = " ";

        output += "/n目前時間: " + date1;

        output += "/n基準時間為: " + longdate;

        output += "/nCLONE時間為: " + date2;

        output += "/n現在到基準時間的毫秒數是: " + date1.getTime();

        date2.setTime(500000000);

        output += "/n現在的時間為: " + date2;

        output += "/n現在到基準時間的毫秒數是:"+date2.getTime();

        output += "/n現在的時間與原來的時間相比較早: " + date2.before(date1);

        output += "/n現在的時間與原來的時間相比較晚: " + date2.after(date1);

        output += "/n現在的時間與原來的時間相比一緻: " + longdate.equals(date1);

        output += "/n現在的時間與原來的時間相比    : " + longdate.compareTo(date1);

        output += "/n原來時間所對應的HASH碼為: " + date1.hashCode();

        output += "/n原來時間的字元串代表時間為: " + date1.toString();

        JOptionPane.showMessageDialog(null, output, "JDK類庫中的時間類 By TANK 5.1",

                                      JOptionPane.PLAIN_MESSAGE);

        System.exit(0);

    }

}

JDK1.5中的類庫---時間類Date
JDK1.5中的類庫---時間類Date
JDK1.5中的類庫---時間類Date