Hi all,
I looking for a way to validate a date which has to have the format 'yyyymmdd'. I found something in the internet:
But this is not exactly what I am looking for:
1. the IllegalArgumentException is never thrown (at least I have not found the 'proper' date format for getting one)
2. the example will take '9' as a valid date because it takes the 9 as: Fri Jan 09 00:00:00 CET 1970
Why do I have a SimpleDateFormat with 'yyMMdd' if the example doesn't care about the presence of all elements of 'yyMMdd' ??
Can anyone help me please?
Cheers
frag
patrick.metz@epost.de
I looking for a way to validate a date which has to have the format 'yyyymmdd'. I found something in the internet:
Code:
import java.util.*;
import java.text.*;
public class jtest {
public static void main(String args[]) {
String dt = "991223";
String fdt = "yyMMdd";
try {
SimpleDateFormat sdf = new SimpleDateFormat(fdt);
sdf.setLenient(false);
Date dt2 = sdf.parse(dt);
System.out.println("Date is ok = " + dt2 + "(" + dt + ")");
}
catch (ParseException e) {
System.out.println(e.getMessage());
}
catch (IllegalArgumentException e) {
System.out.println("Invalid date");
}
}
}
But this is not exactly what I am looking for:
1. the IllegalArgumentException is never thrown (at least I have not found the 'proper' date format for getting one)
2. the example will take '9' as a valid date because it takes the 9 as: Fri Jan 09 00:00:00 CET 1970
Why do I have a SimpleDateFormat with 'yyMMdd' if the example doesn't care about the presence of all elements of 'yyMMdd' ??
Can anyone help me please?
Cheers
frag
patrick.metz@epost.de