In the following code input:
Enter Date: 3/2/2011
Output:
Entered Date is February 3, 2011
Entered Month is 02
Problem is , when i input this date 3/14/2012, the date format function automatically changes month to 12+2(February). If I put 13/15/2011, it will change month to 3(12+3).
It should give an error on 14 that "invalid month"
package lesson4;
import java.util.*;
import java.text.*;
public class ConvertDate {
static String Month;
static String fulldate;
static int month;
static int[] montharray={1,2,3,4,5,6,7,8,9,10,11,12};
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("Enter Date: ");
String ind = sc.nextLine();
//Date now = new Date();
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
SimpleDateFormat f = new SimpleDateFormat("dd");
SimpleDateFormat m = new SimpleDateFormat("MM");
Date d = null;
Date e=null;
Date g=null;
try {
d=df.parse(ind);
e=df.parse(ind);
g=df.parse(ind);
DateFormat df3 = DateFormat.getDateInstance(DateFormat.LONG);
fulldate = df3.format(d);
Month=m.format(g);
month =Integer.parseInt(Month);
String date =f.format(e);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("The entered date is: " + fulldate);
System.out.println("The entered month is: " + Month);
}
}

DateFormatis so much better than string parsing, but forgot thesetLenien(bool)and didn't see another solution before you post your answer ;)