My aim to extract date and month from a date object. I cannot use getDate() and getMonth() , as they are deprecated.
I used the Calendar API, however I am not able to get the desired result. Would you please suggest...
My aim is to extract the month and date as integers.
Scanner input = new Scanner(System.in);
String a;
SimpleDateFormat formatter = new SimpleDateFormat("dd/mm/yyyy");
System.out.println("Please type in your name...");
a = input.nextLine();
System.out.println("You entered the name " + a);
//To print the current date
Date DOB;
Date presentdate = new Date();
System.out.println("Today is " + presentdate);
//To get a birthdate
System.out.println("Enter yout DOB in dd/mm/yyyy");
String b1 = input.nextLine();
DOB = formatter.parse(b1);
System.out.println("Your Date of Birth is" + DOB);
Calendar cal = Calendar.getInstance(); ;
cal.setTime(DOB);
System.out.println(cal);
int month = cal.get(Calendar.MONTH);
int date1 = cal.get(Calendar.DATE);
System.out.println(month);
System.out.println(date1);