Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import java.sql.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class Main {
    /**
     * Method to check if a date is today. Also returns true if the date is
     * earlier than today
     * 
     * @param theDate
     *            the date to see if it is today
     * @return true if theDate is today or earlier
     */
    public static boolean isToday(Date theDate) {
        // Get a calendar with the events start time
        GregorianCalendar theCalendar = new GregorianCalendar();
        theCalendar.setTime(theDate);
        // Get a calendar with current system time to compare with
        Calendar systemCalendar = Calendar.getInstance();
        // If it should return true only if today and not before use == instead
        // of >=
        return systemCalendar.get(Calendar.YEAR) >= theCalendar.get(Calendar.YEAR)
                && systemCalendar.get(Calendar.DAY_OF_YEAR) >= theCalendar.get(Calendar.DAY_OF_YEAR);
    }
}