Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {

    public static void main(String[] args) throws ParseException {

        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");

        String oeStartDateStr = "04/01/2015";
        String oeEndDateStr = "11/14/2015";

        Calendar cal = Calendar.getInstance();
        Integer year = cal.get(Calendar.YEAR);

        oeStartDateStr = oeStartDateStr.concat(year.toString());
        oeEndDateStr = oeEndDateStr.concat(year.toString());

        Date startDate = sdf.parse(oeStartDateStr);
        Date endDate = sdf.parse(oeEndDateStr);
        Date d = new Date();
        String currDt = sdf.format(d);

        if ((d.after(startDate) && (d.before(endDate)))
                || (currDt.equals(sdf.format(startDate)) || currDt.equals(sdf.format(endDate)))) {
            System.out.println("Date is between 1st april to 14th nov...");
        } else {
            System.out.println("Date is not between 1st april to 14th nov...");
        }
    }
}