Returns the smaller of the specified dates. - Java java.util

Java examples for java.util:Date Compare

Description

Returns the smaller of the specified dates.

Demo Code

/**// w w  w  .j  a v a  2s. co  m
 * Copyright (c) 2010 Martin Geisse
 *
 * This file is distributed under the terms of the MIT license.
 */
//package com.java2s;

import java.util.GregorianCalendar;

public class Main {
    /**
     * Returns the smaller of the specified dates. The returned object is the same as one
     * of the arguments, not a clone.
     * @param x the first date
     * @param y the second date
     * @return the smaller one of the arguments
     */
    public static GregorianCalendar min(GregorianCalendar x,
            GregorianCalendar y) {
        return (x.compareTo(y) < 0) ? x : y;
    }
}

Related Tutorials