Tuesday, November 26, 2013

previous 3 Days in java


import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;


public class MainApp {

public static void main(String[] args)
{
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
//lendar[] calender = new Calendar[3];
String[] calender = new String[3];
for (int i = 0; i < 3; i++) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -(i+1));
System.out.println(dateFormat.format(calendar.getTime()));
calender[i] = dateFormat.format(calendar.getTime());
}

Collections.reverse(Arrays.asList(calender));
System.out.println("========================================");

for (int i = 0; i < 3; i++) {
System.out.println(calender[i]);
}


}

}

No comments:

Post a Comment