Why this code is diplaying wrong parsing !!!
I am trying to parse the date which is given by user on command line.
If i give 03/24/2004
its displying "Sat Jan 24 00:03:00 EST 2004" which is wrong.
This is my Code
public class DateFormatExample3 {
public static void main(
String[] args) {
String sDateFormatter = "mm/dd/yyyy";
java.text.SimpleDateFormat format = new SimpleDateFormat(sDateFormatter);
BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in));
try {
System.out.print("ENTER DATE STRING: ");
String dateString = reader.readLine();
while ((dateString != null) && (dateString.length() > 0)) {
try {
Date date = format.parse(dateString);
System.out.println("Original string: " + dateString);
System.out.println("Parsed date : " + date.toString());
System.out.println(); // Skip a line
}
catch(ParseException pe) {
System.out.println(
"ERROR: could not parse date in string \"" +
dateString + "\"");
}
System.out.print("ENTER DATE STRING: ");
dateString = reader.readLine();
}
}
catch(IOException ioe) {
System.out.println("I/O Exception: " + ioe);
}
}
}
My intension is by taking two input dates from user, my method should give an array of DATE object which are all SUNDAYS between these 2 dates.
example:
INPUT:
startDate=03/24/2004
endDate=02/24/2004
OUTPUT:
03/21/2004
03/14/2004
03/07/2004
02/29/2004
Could any one pose some light on this, i need it very urgently
Thanks
swapna