Monday, 30 January 2017

Yesterday's Date using Java code

Java code snipet for Yesterday's Date :

We can use Calendar class to do this job.

                                Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, -1);
SimpleDateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
Date date = cal.getTime();
System.out.println(df2.format(date));
String dateForConsultation = df2.format(date);

No comments:

Post a Comment