1. 程式人生 > 其它 >獲取某一年的某一週的週一//週日的日期

獲取某一年的某一週的週一//週日的日期

//獲取某一年的某一週的週日日期
public static Date getEndDayOfWeekNo(int year, int weekNo) throws ParseException {
Calendar cal = getCalendarFormYear(year);
cal.set(Calendar.WEEK_OF_YEAR, weekNo);
cal.add(Calendar.DAY_OF_WEEK, 6);
//獲得SimpleDateFormat類,我們轉換為yyyy-MM-dd的時間格式
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//注意月份是MM

String start = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" +
cal.get(Calendar.DAY_OF_MONTH);
Date date= java.sql.Date.valueOf(start);
return date;}
//獲取某一年的某一週的週一日期
public static Date getStartDayOfWeekNo(int year, int weekNo) throws ParseException {
Calendar cal = getCalendarFormYear(year);

cal.set(Calendar.WEEK_OF_YEAR, weekNo);
//獲得SimpleDateFormat類,我們轉換為yyyy-MM-dd的時間格式
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//注意月份是MM
String start = cal.get(Calendar.YEAR) + "-" + (cal.get(Calendar.MONTH) + 1) + "-" +
cal.get(Calendar.DAY_OF_MONTH);
Date date= java.sql.Date.valueOf(start);

return date;
}