Java Date Compare compareDates(final String format, final Date date1, final Date date2)

Here you can find the source of compareDates(final String format, final Date date1, final Date date2)

Description

compare Dates

License

Open Source License

Declaration

public static int compareDates(final String format, final Date date1, final Date date2) 

Method Source Code

//package com.java2s;
/**//w  w  w.  j  a v a2s  .c  om
 * Copyright ? 2002 Instituto Superior T?cnico
 *
 * This file is part of FenixEdu Academic.
 *
 * FenixEdu Academic is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * FenixEdu Academic is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with FenixEdu Academic.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.text.DateFormat;

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

public class Main {
    public static int compareDates(final String format, final Date date1, final Date date2) {
        final DateFormat dateFormat = new SimpleDateFormat(format);
        final String date1String = dateFormat.format(date1);
        final String date2String = dateFormat.format(date2);
        return date1String.compareTo(date2String);
    }

    public static String format(final String format, final Date date) {
        return new SimpleDateFormat(format).format(date);
    }
}

Related

  1. compareDateFormat(String strDate1, String strDate2, String format)
  2. compareDateForSecond(Date src, Date target, int second)
  3. compareDates(Date date1, Date date2)
  4. compareDates(Date date1, Date date2)
  5. compareDates(final Date dateA, final Date dateB)
  6. compareDateSequence(String startDate, String endDate)
  7. compareDatesOnly(long date1, long date2)
  8. compareDateTimeNull(Date d1, Date d2)
  9. compareDay(Date date, Date anotherDate)