我已经实现了一种获取当前星期中星期一的日期的方法,并且已经将星期一指定为星期的第一天。
但是,无论我做什么,它都会返回2013年3月24日格林尼治标准时间。我看不到这里的问题。有人能帮忙吗?
public static Date getFirstDayOfWeekDate() { Calendar cal = Calendar.getInstance(); cal.setFirstDayOfWeek(2); cal.set(Calendar.DAY_OF_WEEK, cal.getActualMinimum(Calendar.DAY_OF_WEEK)); Date firstDayOfTheWeek = cal.getTime(); return firstDayOfTheWeek; }
试试这个 :
public static Date getFirstDayOfWeekDate() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.DAY_OF_WEEK, cal.getActualMinimum(Calendar.DAY_OF_WEEK)); Date now = new Date(); cal.setTime(now); int week = cal.get(Calendar.DAY_OF_WEEK); return new Date(now.getTime() - 24 * 60 * 60 * 1000 * (week - 1)); }