/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.time.format.DateTimeFormatter;
import java.time.LocalDate;
import java.time.format.DateTimeParseException;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
System.
out.
println("Esta data é válida! " + new DateValidator
().
isValid("10/12/2017")); System.
out.
println("Esta data é inválida! " + new DateValidator
().
isValid("10122017")); }
}
class DateValidator {
public boolean isValid
(String date
) { try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
LocalDate d = LocalDate.parse(date,formatter);
return true;
} catch (DateTimeParseException e) {
return false;
}
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CmltcG9ydCBqYXZhLnRpbWUuZm9ybWF0LkRhdGVUaW1lRm9ybWF0dGVyOwppbXBvcnQgamF2YS50aW1lLkxvY2FsRGF0ZTsKaW1wb3J0IGphdmEudGltZS5mb3JtYXQuRGF0ZVRpbWVQYXJzZUV4Y2VwdGlvbjsKCi8qIE5hbWUgb2YgdGhlIGNsYXNzIGhhcyB0byBiZSAiTWFpbiIgb25seSBpZiB0aGUgY2xhc3MgaXMgcHVibGljLiAqLwpjbGFzcyBJZGVvbmUKewoJcHVibGljIHN0YXRpYyB2b2lkIG1haW4gKFN0cmluZ1tdIGFyZ3MpIHRocm93cyBqYXZhLmxhbmcuRXhjZXB0aW9uCgl7CgkJU3lzdGVtLm91dC5wcmludGxuKCJFc3RhIGRhdGEgw6kgdsOhbGlkYSEgIiArIG5ldyBEYXRlVmFsaWRhdG9yKCkuaXNWYWxpZCgiMTAvMTIvMjAxNyIpKTsKCQlTeXN0ZW0ub3V0LnByaW50bG4oIkVzdGEgZGF0YSDDqSBpbnbDoWxpZGEhICIgKyBuZXcgRGF0ZVZhbGlkYXRvcigpL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