Check String value is a valid date or not | Code Factory

package com.codeFactory;import java.text.ParseException;
import java.text.SimpleDateFormat;
public class Main {
public static boolean checkDate(String inDate) {
/* SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); */
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
try {
dateFormat.parse(inDate.trim());
} catch (ParseException pe) {
return false;
}
return true;
}
public static void main(String[] args) {
/* System.out.println(checkDate("30-03-2017")); */
System.out.println(checkDate("2017-02-28"));
}
}

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store