怎样使Calendar类可以将指定日期的的一周的日历表示出来。。

2025-01-07 07:47:28
推荐回答(1个)
回答1:

/**
* 取得当前日期所在周的第一天
*/
public Date getFirstDayOfWeek(Date date)
{
Calendar c = Calendar.getInstance();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setTime(date);
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); // 星期一
return c.getTime ();
}
/**
* 取得当前日期所在周的最后一天
*/
public Date getLastDayOfWeek(Date date)
{
Calendar c = Calendar.getInstance();
c.setFirstDayOfWeek(Calendar.MONDAY);
c.setTime(date);
c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6); //星期天
return c.getTime();
}