你的位置:首页 > Java教程

[Java教程]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);}}