Java获取某年某周的最后一天

package test;

import java.text.SimpleDateFormat;
import java.util.Calendar;
/**
 * ClassName: LastDayOfWeek 
 * @Description: TODO
 * @author Owen
 * @date 2015年12月22日
 */
public class LastDayOfWeek
{
/**
* 获取某年某周的最后一天
* @Title:getLastDayOfWeek
* @Description:
* @param:@param year
* @param:@param week
* @param:@return
* @return:String
* @throws
*/
public static String getLastDayOfWeek(int year,int week)
{
Calendar cal = Calendar.getInstance();
//设置年份
cal.set(Calendar.YEAR,year);
//设置周
cal.set(Calendar.WEEK_OF_YEAR, week);
//设置该周第一天为星期一
cal.setFirstDayOfWeek(Calendar.MONDAY);
//设置最后一天是星期日
cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek() + 6); // Sunday
//格式化日期
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String lastDayOfWeek = sdf.format(cal.getTime());
return lastDayOfWeek;
}
/**
* @Title:main
* @Description:
* @param:@param args
* @return: void
* @throws
*/
public static void main(String[] args)
{
String lastDay = getLastDayOfWeek(2015,22);
System.out.println("2014年第22周的最后一天是:" + lastDay);
}
}

  

posted @ 2015-12-22 11:07  欧文_Owen  阅读(1488)  评论(0编辑  收藏  举报