Java Date Format Pattern isEqual(String d1, String d2, String format)

Here you can find the source of isEqual(String d1, String d2, String format)

Description

is Equal

License

Apache License

Declaration

public static boolean isEqual(String d1, String d2, String format) 

Method Source Code


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

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

import java.util.Date;

public class Main {

    public static boolean isEqual(String d1, String d2, String format) {
        Date d1Date = toDate(d1, format);
        Date d2Date = toDate(d2, format);
        if (d1Date.getTime() == d2Date.getTime())
            return true;
        return false;
    }/* w w  w.ja v a 2  s  .  co m*/

    public static Date toDate(String str) {
        if (null == str || str.trim().isEmpty()) {
            return null;
        }
        try {
            DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return fmt.parse(str);
        } catch (ParseException e) {
            return null;
        }
    }

    public static Date toDate(String dateString, String format) {
        try {
            DateFormat fmt = new SimpleDateFormat(format);
            return fmt.parse(dateString);
        } catch (ParseException e) {
            return null;
        }
    }

    public static long getTime(String s) {
        return parseMysql(s).getTime();
    }

    public static Date parseMysql(String s) {
        try {
            DateFormat fmtTemp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return fmtTemp.parse(s);
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

  1. getSdf(String formatPattern)
  2. getSimpleDataFormattedFile(File file)
  3. getSortedTimetampFormat()
  4. getStringAcordFormat()
  5. getSupportedFormats()
  6. isValidFormat(String format, String value)
  7. log(String format, Object... args)
  8. logFormat(String msg)
  9. subFiles(String formatString, File[] files)