5

我想获取当前的星期日期

让我们想想:今天是星期二 07.05.2013。我想得到一个包含日期的工作日列表

我怎样才能做到这一点 ?

Sunday 05.05.2013
Monday 06.05.2013
*Tuesday 07.05.2013
Wednesday 08.05.2013
Thursday 09.05.2013
Friday 10.05.2013
Saturday 11.05.2013
4

2 回答 2

15

此代码将使用系统一周的第一天工作,这可能与星期日不同。

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek());
    SimpleDateFormat sdf = new SimpleDateFormat("EEEE dd.MM.yyyy");

    for (int i = 0; i < 7; i++) {
        Log.i("dateTag", sdf.format(cal.getTime()));
        cal.add(Calendar.DAY_OF_WEEK, 1);
    }
于 2013-05-05T19:57:22.823 回答
1

试试这个->

Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_MONTH, 5);
c.set(Calendar.MONTH, 7);
c.set(Calendar.YEAR, 2013);

int weekNo = c.get(Calendar.WEEK_OF_YEAR);
c.set(Calendar.WEEK_OF_YEAR, weekNo);

c.clear();

c.set(Calendar.WEEK_OF_YEAR, weekNo);
c.set(Calendar.YEAR, 2013);


SimpleDateFormat formatter = new SimpleDateFormat("EEE dd/MM/yyyy"); 
Date startDate = c.getTime();
c.add(Calendar.DATE, 1);
for (int i = 0; i < 5; i++) {
    Log.d(formatter.format(c.getTime()));
    c.add(Calendar.DATE, 1);
}
于 2013-05-05T19:38:17.487 回答