compare Date - Java java.util

Java examples for java.util:Date Compare

Description

compare Date

Demo Code


//package com.java2s;

import java.util.Date;

public class Main {
    public static void main(String[] argv) throws Exception {
        Date date = new Date();
        System.out.println(compareDate(date));
    }/*from  ww  w . j a  v a 2s.  co m*/

    public static long compareDate(Date date) {
        return compareDate(new Date(), date);
    }

    public static long compareDate(Date nearDate, Date farDate) {
        long nearMilli = nearDate.getTime();
        long farMilli = farDate.getTime();
        long result = nearMilli - farMilli;
        if (result < 0) {
            result = -result;
        }
        return result;
    }
}

Related Tutorials