Java Time Format validateDatetimeString(String datetimeString, String format)

Here you can find the source of validateDatetimeString(String datetimeString, String format)

Description

validate Datetime String

License

Open Source License

Declaration

public static boolean validateDatetimeString(String datetimeString,
        String format) 

Method Source Code

//package com.java2s;

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

public class Main {

    public static boolean validateDatetimeString(String datetimeString,
            String format) {//  w w w .  j  av  a  2 s.c  o m
        if (datetimeString == null || datetimeString.equals("")) {
            return false;
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        try {
            sdf.parse(datetimeString);
            return true;
        } catch (ParseException e) {
            return false;
        }
    }
}

Related

  1. toString(Date time, String format)
  2. toString(String format, long time)
  3. toString(String format, long time)
  4. toStringFormatTime(long time, String format)
  5. tryToParse(String datetime, SimpleDateFormat format)