0

我可以列出当前的星期日期。但是如何列出前一周/下一周的日期?

(我想用一个按钮来列出前一周和下一周的日子。每当我点击它会显示一周前/一周后)

Calendar cal = Calendar.getInstance(Locale.UK);     
        cal.set(Calendar.DAY_OF_WEEK,  cal.getFirstDayOfWeek());        
        daydate = new SimpleDateFormat("dd.MM.yyyy");       

        for (int i = 0; i < 7; i++) {   
             dates[i] = daydate.format(cal.getTime());     
            cal.add(Calendar.DAY_OF_WEEK, 1);
}
4

2 回答 2

1

要在下周显示,请遵循以下代码。

    List next = new ArrayList();
    for (int i = 0; i < 7; i++) {
    c.add(Calendar.DATE, 1);
    start = df.format(c.getTime());
    next.add(start);
    }
   textview.setText("" + next.get(0) + "-" + next.get(6));
于 2018-05-03T10:13:13.740 回答
0

要显示前一周,请遵循以下代码:

    List previous = new ArrayList();
            for (int i = 0; i < 7; i++) {
                c.add(Calendar.DATE, -1);
                start = df.format(c.getTime());
                previous.add(start);
            }
            textview.setText("" + previous.get(6) + "-" + previous.get(0));
于 2018-05-03T10:16:39.077 回答