1

After entering the date in the specified format as input. how can I get the day, month and year and include them in three distinct variables? I tried with getYear () but it gives me a mistake because it is deprecated, I read that you can with "Calendar" but I did not understand how to use it in this library

System.out.println("Inserisci la data [yyyy-MM-dd]: ");
Scanner in = new Scanner(System.in);
s = in.nextLine();
//converte la stringa della data in un oggetto di classe Date
SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");
Date d = formato.parse(s);
Veliko
  • 747
  • 1
  • 9
  • 25
Gaetano
  • 145
  • 1
  • 5
  • 19

1 Answers1

1
Calendar c = new Calendar();
c.setTime(yourDate);
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);