-1
//explain
public class DateLoop {
    static String finalDate; 
    static String particularDate;

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        SimpleDateFormat sdf = new SimpleDateFormat("d-M-yyyy ");
        Calendar cal = Calendar.getInstance();
        particularDate = "2-1-2018";
        // get starting date
        cal.add(Calendar.DAY_OF_YEAR, -7);

        // loop adding one day in each iteration
        for(int i = 0; i< 7; i++){
            cal.add(Calendar.DAY_OF_YEAR, 1);
            finalDate =sdf.format(cal.getTime());
            System.out.println(finalDate);
            //ie, its giving previous 7 dates from present date, but I want
            //particular date... thanks in advance
        }
    }

}

つまり、現在の日付から前の 7 日付を指定しますが、特定の日付から前の 7 日付が必要です。

4

3 に答える 3