if two date is the same day - Java java.util

Java examples for java.util:Day

Description

if two date is the same day

Demo Code


//package com.java2s;

import java.util.Calendar;

public class Main {
    /**//from ww  w  . j  a  va  2  s . c o  m
     * if two date is the same day, for example ,1999-11-21 00:00:00 and  1999-11-21 23:15:40 are in same day,
     * but 1999-11-21 00:00:00 and 2010-11-21 00:00:00 are not
     *
     * @param ltime
     * @param rtime
     * @return
     */
    public static boolean sameDay(long ltime, long rtime) {
        Calendar l = Calendar.getInstance();
        Calendar r = Calendar.getInstance();
        l.setTimeInMillis(ltime);
        r.setTimeInMillis(rtime);

        return l.get(Calendar.YEAR) == r.get(Calendar.YEAR)
                && l.get(Calendar.MONTH) == r.get(Calendar.MONTH)
                && l.get(Calendar.DAY_OF_MONTH) == r
                        .get(Calendar.DAY_OF_MONTH);
    }
}

Related Tutorials