is Today's Date Calendar - Android java.util

Android examples for java.util:Today

Description

is Today's Date Calendar

Demo Code


//package com.java2s;

import java.util.Calendar;

public class Main {
    /**//from www  .java 2  s  . c  om
     *
     * @param calendar
     * @return
     */
    public static boolean isToday(Calendar calendar) {
        return isSameDay(calendar, Calendar.getInstance());
    }

    /**
     *
     * @param cal1
     * @param cal2
     * @return
     */
    public static boolean isSameDay(Calendar cal1, Calendar cal2) {
        if (cal1 == null || cal2 == null)
            throw new IllegalArgumentException("The dates must not be null");
        return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA)
                && (cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)) && (cal1
                    .get(Calendar.DAY_OF_YEAR) == cal2
                .get(Calendar.DAY_OF_YEAR)));
    }
}

Related Tutorials