Java Today isToday(int dateInt)

Here you can find the source of isToday(int dateInt)

Description

is Today

License

Open Source License

Declaration

public static boolean isToday(int dateInt) 

Method Source Code


//package com.java2s;

import java.util.*;

public class Main {
    private static HashMap<Integer, Calendar> ctcMemo = new HashMap<>();

    public static boolean isToday(int dateInt) {
        Calendar nowCal = GregorianCalendar.getInstance();
        nowCal.setTime(new Date());
        Calendar compareCal = convertToCal(dateInt);
        return nowCal.get(Calendar.DAY_OF_MONTH) == compareCal.get(Calendar.DAY_OF_MONTH)
                && nowCal.get(Calendar.MONTH) == compareCal.get(Calendar.MONTH)
                && nowCal.get(Calendar.YEAR) == compareCal.get(Calendar.YEAR);

    }// ww w  . j  a  v  a  2 s.  c  om

    /**
     * converts dateInt to Calendar
     *
     * @param dateInt date int to convert
     * @return calendar value
     */
    private static Calendar convertToCal(int dateInt) {
        Calendar result = ctcMemo.get(dateInt);
        if (result != null) {
            return result;
        }

        Calendar gc = new GregorianCalendar();
        gc.setTime(convertToDate(dateInt));

        ctcMemo.put(dateInt, gc);
        return gc;
    }

    /**
     * converts dateInto to date
     *
     * @param dateInt dateInt to be converted
     * @return date
     */
    public static Date convertToDate(int dateInt) {
        @SuppressWarnings("deprecation")
        Date nd = new Date(dateInt / 10000 - 1900, (dateInt / 100) % 100 - 1, dateInt % 100);

        return nd;
    }
}

Related

  1. isToday(Date date, TimeZone timezone)
  2. isToday(Date dateTime)
  3. isToday(final Date date)
  4. isToday(final Date date)
  5. isToday(final Date date)
  6. isToDay(long millis)
  7. isToday(long milliseconds)
  8. isToday(long timestamp)
  9. isToday(String depDateTime)