从设置日期 JAVA 获取本周所有日期的列表

Get a list of all the dates for the week from set date JAVA

基本上,我试图创建一个从设定日期开始的一周内所有日期的列表,并将其存储在 String[] 数组中。但是我遇到了一些麻烦。

基本上,今天是 09/03/2016 所以在 String[] 数组中我要存储:

09/03/2016
10/03/2016
11/03/2016
12/03/2016
13/03/2016
14/03/2016
15/03/2016

这是我的代码:

        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek() - calendar.get(Calendar.DAY_OF_WEEK));
        String[] weekly = new String[7];
        Arrays.fill(weekly, "");
        int today = calendar.getInstance().get(Calendar.DAY_OF_WEEK);
        for(int i=today; i <= today-1; i++){
            weekly[i] = Integer.toString(i);
            System.out.println(i);
        }

如果有人能帮助我就太好了

我不明白这个 for 循环是如何工作的

for(int i=today; i <= today-1; i++){

如果您将值 today 分配给 i,那么它已经大于 today - 1

此外,您甚至没有在循环中使用 calendar

怎么样

for (int i = 0; i < 7; i++) {
    Date dt = calendar.getTime ();
    // now format it using SimpleDateFormat
    String val = df.format (dt);
    weekly[i] = val;
    calendar.add (Calendar.DAY_OF_WEEK, 1);
}