Java Today isToday(final Date date)

Here you can find the source of isToday(final Date date)

Description

is Today

License

LGPL

Declaration

public static boolean isToday(final Date date) 

Method Source Code

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

import java.util.*;

public class Main {
    /**// w  ww .  j a va2 s . co m
     * Day=5 *
     */
    public static final int DAY = Calendar.DAY_OF_MONTH;
    /**
     * MONTH=2 *
     */
    public static final int MONTH = Calendar.MONTH;
    /**
     * Year=1 *
     */
    public static final int YEAR = Calendar.YEAR;

    public static boolean isToday(final Date date) {
        final Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        final int year = calendar.get(YEAR);
        final int month = calendar.get(MONTH);
        final int day = calendar.get(DAY);
        final Calendar today = Calendar.getInstance();
        today.setTime(now());
        final int tyear = today.get(YEAR);
        final int tmonth = today.get(MONTH);
        final int tday = today.get(DAY);
        final boolean result = tyear == year && tmonth == month && tday == day;
        return result;
    }

    public static Date now() {
        return new Date();
    }
}

Related

  1. isToday(Date d1)
  2. isToday(Date date)
  3. isToday(Date date)
  4. isToday(Date date, TimeZone timezone)
  5. isToday(Date dateTime)
  6. isToday(final Date date)
  7. isToday(final Date date)
  8. isToday(int dateInt)
  9. isToDay(long millis)