fork download
  1. import java.text.ParsePosition;
  2. import java.time.LocalDate;
  3. import java.time.format.DateTimeFormatter;
  4. import java.util.Locale;
  5.  
  6. public class Main {
  7. public static void main(String[] args) {
  8. String[] arr = { "2015-02-02", "2015-02-02 23:23:23" };
  9. DateTimeFormatter dtf = DateTimeFormatter.ofPattern("uuuu-MM-dd", Locale.ENGLISH);
  10.  
  11. for (String s : arr) {
  12. LocalDate.from(dtf.parse(s, pp));
  13. if (pp.getIndex() < s.length()) {
  14. System.out.println("'" + s + "' is not a date string as per the specified date pattern.");
  15. }
  16. }
  17. }
  18. }
Success #stdin #stdout 0.11s 53540KB
stdin
Standard input is empty
stdout
'2015-02-02 23:23:23' is not a date string as per the specified date pattern.