Java Second Format compareDate(String fistDate, String secondDate, String format)

Here you can find the source of compareDate(String fistDate, String secondDate, String format)

Description

compare Date

License

Apache License

Declaration

public static boolean compareDate(String fistDate, String secondDate, String format) throws ParseException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Main {
    private static Map<String, SimpleDateFormat> formats = new HashMap();

    public static boolean compareDate(String fistDate, String secondDate, String format) throws ParseException {
        boolean flag = false;

        Date fist = null;// ww w .j  av a  2 s.com
        Date second = null;

        fist = getDateFromString(fistDate, format);

        second = getDateFromString(secondDate, format);
        if (fist.before(second)) {
            flag = true;
        }

        return flag;
    }

    public static Date getDateFromString(String date, String pattern) throws ParseException {
        SimpleDateFormat sDateFormat = getDateFormat(pattern);

        synchronized (sDateFormat) {
            return sDateFormat.parse(date);
        }
    }

    public static SimpleDateFormat getDateFormat(String pattern) {
        SimpleDateFormat sDateFormat = (SimpleDateFormat) formats.get(pattern);
        if (sDateFormat == null) {
            sDateFormat = new SimpleDateFormat(pattern);
            formats.put(pattern, sDateFormat);
        }
        return sDateFormat;
    }
}

Related

  1. _toSeconds(String strTime)
  2. addSecondCa(String d1, int timeSpan, String format)
  3. calculateTimeInSeconds(long startTimeInMilliseconds, long endTimeInMilliseconds)
  4. changeSecondsToTime(long seconds)
  5. elapsedSeconds(long startTime)
  6. elapsedSeconds2(long milli)
  7. formatMiliSeconds(long time)
  8. formatMilliIntervalAsSeconds(long interval)