Check if the first calendar is actually dated before the second calendar. - Java java.util

Java examples for java.util:Second

Description

Check if the first calendar is actually dated before the second calendar.

Demo Code


//package com.java2s;
import java.util.Calendar;

public class Main {
    public static void main(String[] argv) throws Exception {
        Calendar before = Calendar.getInstance();
        Calendar after = Calendar.getInstance();
        checkBeforeAfter(before, after);
    }//w w w.java 2 s .c o  m

    /**
     * Check if the first calendar is actually dated before the second calendar.
     *
     * @param before The first calendar with expected date before the second
     * calendar.
     * @param after The second calendar with expected date after the first
     * calendar.
     */
    private static void checkBeforeAfter(Calendar before, Calendar after) {
        if (before.after(after)) {
            throw new IllegalArgumentException(
                    "The first calendar should be dated before the second calendar.");
        }
    }
}

Related Tutorials