I have an existing program that I have to correct . It contains these lines :
Date startDate = new Date();
int day = startDate.getDate() - 1;
but getDate() from the type Date is deprecated so i have to change it using Calender. I tried this :
Calendar startDate = Calendar.getInstance();
startDate.add(Calendar.DATE, -1);
int day= startDate.getTime();
but this results into following error :
Type mismatch: cannot convert from Date to int
One more good option is to use like :
System.out.println(DateFormat.getDateInstance().format(new Date()));
It will print the current date.
If you need time along with date then you can use like :
System.out.println(DateFormat.getDateTimeInstance().format(new Date()));