/** * @Title:FirstDayOfWeek.java * @Package:com.you.freemarker.model * @Description:获取某年某周的第一天 * @author:Youhaidong(游海东) * @date:2014-5-29 下午11:29:53 * @version V1.0 */ package com.you.freemarker.model; import java.text.SimpleDateFormat; import java.util.Calendar; /** * 类功能说明 * 类修改者 修改日期 * 修改说明 * <p>Title:FirstDayOfWeek.java</p> * <p>Description:游海东个人开发</p> * <p>Copyright:Copyright(c)2013</p> * @author:游海东 * @date:2014-5-29 下午11:29:53 * @version V1.0 */ public class FirstDayOfWeek { /** * 获取某年某周的第一天 * @Title:getFirstDayOfWeek * @Description: * @param:@param year * @param:@param week * @param:@return * @return:String * @throws */ public static String getFirstDayOfWeek(int year,int week) { Calendar cal = Calendar.getInstance(); //设置年份 cal.set(Calendar.YEAR,year); //设置周 cal.set(Calendar.WEEK_OF_YEAR, week); //设置该周第一天为星期一 cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); //格式化日期 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String firstDayOfWeek = sdf.format(cal.getTime()); return firstDayOfWeek; } /** * @Title:main * @Description: * @param:@param args * @return: void * @throws */ public static void main(String[] args) { String firstDay = getFirstDayOfWeek(2014,22); System.out.println("2014年第22周的第一天是:" + firstDay); } }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/10970.html