Returns true if the two given calendars are dated on the same time. - Java java.util

Java examples for java.util:Calendar Calculation

Description

Returns true if the two given calendars are dated on the same time.

Demo Code


//package com.java2s;
import java.util.Calendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        Calendar one = Calendar.getInstance();
        Calendar two = Calendar.getInstance();
        System.out.println(sameTime(one, two));
    }//from w w w .j  ava 2  s  . c  om

    /**
     * Returns <tt>true</tt> if the two given calendars are dated on the same
     * time. The difference from <tt>one.equals(two)</tt> is that this method
     * does not respect the time zone.
     * 
     * @param one
     *            The one calendar.
     * @param two
     *            The other calendar.
     * @return True if the two given calendars are dated on the same time.
     */
    public static boolean sameTime(Calendar one, Calendar two) {
        return one.getTimeInMillis() == two.getTimeInMillis();
    }
}

Related Tutorials