Reputation: 131
public static boolean checkTimeFormat(String str){
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.parse(str);
return true;
} catch (ParseException ex) {
System.out.println("not a valid time:"+str);
//ex.printStackTrace();
}
return false;
}
I have this method to check whether str in the correct format I tested it against
2015–01-01 07:01:14
and it says not a valid time. I am confused as they are in the same format.
Upvotes: 4
Views: 78