I know that this must have been implemented a million times, but I'm here looking for ideas:
I need to validate the date for a specific format. I have both the inputs (date format and the actual date) as String objects. I can use a variety of API's to do this (Calendar, SimpleDateFormat, DateUtils etc., ) but I would like to have suggestions on the simplest one.
For example: isDateValid("DDMMYYYY", "21122010")
In all my date formats, I do not have any seperators (like . or -). It is always either DDMM or DDMMYYYY or any of that combination but always without a seperator.
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
And remember that the pattern characters are case sensitive. YYYY is invalid, and DD returns the day of the year, not the day of the month. You want "ddMMyyyy" or "ddMM". Because yes, MM should remain uppercase as mm is reserved for minutes.
Calendar has a method called getActualMaximum; it uses its current date/time to determine the result. So getActualMaximum(Calendar.DAY_OF_MONTH) would return 28 if the calendar's date was in February, and 30 for this month.
Don't confuse this method with getMaximum which will return the absolute maximum; getMaximum(Calendar.DAY_OF_MONTH) would return 31, whatever the calendar's date would be.
Joe Harry wrote:Nope it still prints the wrong values:
Could you please explain why position.getIndex() == date.length(); condition is needed in the return statement above? Can't we just use d!=null?
[size=9]PS: Am new user of SimpleDateFormat and might not be fully aware of its functionality.[/size]