Compares two date time objects as to whether their date parts are equal. - Java java.util

Java examples for java.util:Date Compare

Description

Compares two date time objects as to whether their date parts are equal.

Demo Code

/**//from w ww.j a v  a  2  s  . c  o  m
 * Copyright (c) 2010 Martin Geisse
 *
 * This file is distributed under the terms of the MIT license.
 */
//package com.java2s;
import java.util.Calendar;

import java.util.GregorianCalendar;

public class Main {
    /**
     * Compares two datetime objects as to whether their date parts are equal.
     * @param x the first datetime object to compare
     * @param y the second datetime object to compare
     * @return true if the date parts are equal, false if not
     */
    public static boolean dateEquals(GregorianCalendar x,
            GregorianCalendar y) {
        return (x.get(Calendar.YEAR) == y.get(Calendar.YEAR))
                && (x.get(Calendar.MONTH) == y.get(Calendar.MONTH))
                && (x.get(Calendar.DAY_OF_MONTH) == y
                        .get(Calendar.DAY_OF_MONTH));
    }
}

Related Tutorials