Java.util.Date.compareTo() 方法


Java.util.Date.compareTo() 方法

package com.codingdict;

import java.util.*;

public class DateDemo {
   public static void main(String[] args) {

      // create two dates
      Date date = new Date(98, 5, 21);
      Date date2 = new Date(99, 1, 9);

      // make 3 comparisons with them
      int comparison = date.compareTo(date2);
      int comparison2 = date2.compareTo(date);
      int comparison3 = date.compareTo(date);

      // print the results
      System.out.println("Comparison Result:" + comparison);
      System.out.println("Comparison2 Result:" + comparison2);
      System.out.println("Comparison3 Result:" + comparison3);
   }
}