Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.Calendar;
import java.util.Date;

public class Main {
    public static boolean between(Calendar date, Calendar date1, Calendar date2) {
        if ((compare(date, date1) == 0) && (compare(date, date2) == 0)) {
            return true;
        }

        if ((compare(date, date1) == -1) || (compare(date, date2) == 1)) {
            return false;
        }
        return true;
    }

    public static boolean between(Date date, Date date1, Date date2) {
        if (date.getTime() >= date1.getTime() && date.getTime() <= date2.getTime()) {
            return true;
        }
        return false;
    }

    public static int compare(Calendar date1, Calendar date2) {
        int i = date1.get(Calendar.YEAR);
        int j = date2.get(Calendar.YEAR);

        if (i > j)
            return 1;
        if (i < j)
            return -1;

        i = date1.get(Calendar.MONTH);
        j = date2.get(Calendar.MONTH);
        if (i > j)
            return 1;
        if (i < j)
            return -1;

        i = date1.get(Calendar.DAY_OF_MONTH);
        j = date2.get(Calendar.DAY_OF_MONTH);
        if (i > j)
            return 1;
        if (i < j)
            return -1;

        i = date1.get(Calendar.HOUR_OF_DAY);
        j = date2.get(Calendar.HOUR_OF_DAY);
        if (i > j)
            return 1;
        if (i < j)
            return -1;

        i = date1.get(Calendar.MINUTE);
        j = date2.get(Calendar.MINUTE);
        if (i > j)
            return 1;
        if (i < j)
            return -1;

        i = date1.get(Calendar.SECOND);
        j = date2.get(Calendar.SECOND);
        if (i > j)
            return 1;
        if (i < j)
            return -1;

        return 0;
    }
}