Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DateFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Scanner;
- /**
- *
- * @author hendri
- */
- public class JavaApplication1 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- System.out.println("Ketikkan tanggal: ");
- String tgl = in.next();
- if (isDateValid(tgl))
- System.out.println("Tanggal "+tgl+" valid !");
- else
- System.out.println("Tanggal "+tgl+" tidak valid !");
- }
- public static boolean isDateValid(String date) {
- try {
- DateFormat df = new SimpleDateFormat("dd-MM-yyyy");
- df.setLenient(false);
- df.parse(date);
- return true;
- } catch (ParseException e) {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement