Java obtains the first day of a week of a year.
1. Design source code
FirstDayOfWeek. java:
/*** @ Title: FirstDayOfWeek. java * @ Package: com. you. freemarker. model * @ Description: Get the first day of a week of a year * @ author: Youhaidong (Youhaidong) * @ date: 11:29:53 * @ version V1.0 */package com. you. freemarker. model; import java. text. simpleDateFormat; import java. util. calendar;/*** class Function Description * class modifier modification date * modification Description *Title: FirstDayOfWeek. java
*Description: Personal Development of youhaidong
*Copyright: Copyright (c) 2013
* @ Author: You Haidong * @ date: 11:29:53 * @ version V1.0 */public class FirstDayOfWeek {/*** get the first day of a week of a year * @ Title: getFirstDayOfWeek * @ Description: * @ param: @ param year * @ param: @ param week * @ param: @ return * @ return: string * @ throws */public static String getFirstDayOfWeek (int year, int week) {Calendar ar cal = Calendar ar. getInstance (); // set the year cal. set (Calendar. YEAR, year); // set weekly cal. set (Calendar. WEEK_OF_YEAR, week); // set the first day of the week to Monday cal. set (Calendar. DAY_OF_WEEK, Calendar. MONDAY); // format the date 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 (hz22); System. out. println ("the first day of week 1, 22nd is:" + firstDay );}}
2. Running result
The first day of week 12, 22nd is 2014