Java Date Format Pattern isValidFormat(String format, String value)

Here you can find the source of isValidFormat(String format, String value)

Description

Date string format validate

License

Apache License

Parameter

Parameter Description
format a parameter
value a parameter

Declaration

public static boolean isValidFormat(String format, String value) 

Method Source Code

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

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

import java.util.Date;

public class Main {
    /**/*from  w w w . ja  v a2 s. c o  m*/
     * Date string format validate
     * 
     * @param format
     * @param value
     * @return
     */
    public static boolean isValidFormat(String format, String value) {
        Date date = null;
        try {
            SimpleDateFormat formatter = new SimpleDateFormat(format);
            formatter.setLenient(false); //make it strict
            date = formatter.parse(value);
        } catch (ParseException ex) {
            return false;
        }
        return date != null;
    }
}

Related

  1. getSimpleDataFormattedFile(File file)
  2. getSortedTimetampFormat()
  3. getStringAcordFormat()
  4. getSupportedFormats()
  5. isEqual(String d1, String d2, String format)
  6. log(String format, Object... args)
  7. logFormat(String msg)
  8. subFiles(String formatString, File[] files)
  9. subtraiHora(String horaFim, String horaIni, String formatoHora)