Java obtains the last day of a week and the last day of java.

Source: Internet
Author: User

Java obtains the last day of a week and the last day of java.

Package test; import java. text. simpleDateFormat; import java. util. calendar;/*** ClassName: LastDayOfWeek * @ Description: TODO * @ author Owen * @ date July 15, December 22, 2015 */public class LastDayOfWeek {/*** obtain the last day of a week of a year * @ 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 (); // 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. setFirstDayOfWeek (Calendar. MONDAY); // set the last day to Sunday cal. set (Calendar. DAY_OF_WEEK, cal. getFirstDayOfWeek () + 6); // Sunday // format the date 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 (13722); System. out. println ("the last day of week 1, 22nd is:" + lastDay );}}

  

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.