Java Date Compare by Day isSameDayWithToday(Date date)

Here you can find the source of isSameDayWithToday(Date date)

Description

is Same Day With Today

License

Apache License

Declaration

public static boolean isSameDayWithToday(Date date) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static boolean isSameDayWithToday(Date date) {

        if (date == null) {
            return false;
        }//  ww  w . j a  va 2s .c  om

        Calendar todayCal = Calendar.getInstance();
        Calendar dateCal = Calendar.getInstance();

        todayCal.setTime(new Date());
        dateCal.setTime(date);
        int subYear = todayCal.get(Calendar.YEAR) - dateCal.get(Calendar.YEAR);
        int subMouth = todayCal.get(Calendar.MONTH) - dateCal.get(Calendar.MONTH);
        int subDay = todayCal.get(Calendar.DAY_OF_MONTH) - dateCal.get(Calendar.DAY_OF_MONTH);
        if (subYear == 0 && subMouth == 0 && subDay == 0) {
            return true;
        }
        return false;
    }
}

Related

  1. isSameDay(Date date1, Date date2)
  2. isSameDay(Date date1, Date date2)
  3. isSameDay(Date day1, Date day2)
  4. isSameDay(Date lastUpgradeTime)
  5. isSameDay(final Date date1, final Date date2)
  6. sameDay(Date date1, Date date2)
  7. sameDay(Date date1, Date date2)
  8. sameDay(Date date1, Date date2)
  9. sameDay(Date date1, Date date2)