Originally posted by lijun wang:
how to validate a string like "20060503" is DATE?how to validate this string are all number, not charactor?
Originally posted by Jeff Albertson:
I hope you realize that asking if the string is a valid date is very different from asking whether it consists of only numbers!!!
For the date question, definitely use a SimpleDateFormat -- rolling your own would be silly. (Leap years, the start of the Gregorian calendar...)
Parses text from the beginning of the given string to produce a date. The method may not use the entire text of the given string.
...more information in parse(String, ParsePosition)
By default, parsing is lenient: If the input is not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).
Originally posted by Ken Blair:
If it can be either it would default to MDY. Of course 990505 would fail an MDY parse because 99 is not a valid month and then get parsed as YMD.