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.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    public static boolean equalDate(String date) {
        Date todayDate = null;
        Date inputDate = null;
        Date thirdDate = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String today = sdf.format(new Date());
        Calendar cal = Calendar.getInstance();
        //      cal.add(Calendar.DATE, -1);      
        //      String today = sdf.format(cal.getTime());
        try {
            todayDate = sdf.parse(today);
            inputDate = sdf.parse(date);
            cal.setTime(inputDate);
            cal.add(Calendar.DATE, 3);
            thirdDate = cal.getTime();
            if (todayDate.compareTo(inputDate) >= 0 && todayDate.compareTo(thirdDate) < 0) {
                return true;
            } else {
                return false;
            }
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }

    }
}