Java obtains the first day of a week of a year.

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.