How to check String is a valid date or not in java | Code Factory

Check String value is a valid date or not.




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(isValidDate("30-03-2017")); */
System.out.println(checkDate("2017-02-28"));
}
}

Comments

Popular posts from this blog

How to get IP address and MAC address of client in java | #CodeFactory

At Least One Checkbox Is Checked From All CheckBox Group | #CodeFactory

FTP Connection In Installed Alfresco | Code Factory