I am using the following code to get today's date.
Calendar cal = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
return dateFormat.format(cal.getTime());
But I also want yesteday date to be in the same format.
I use
Calendar cal = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
cal.add(Calendar.DATE, -1);
return dateFormat.format(cal.getTime());
but I feel that it will work after changing the month or year. How can i solve this. Help is greatly appreciated.
Ash s source
share