Java gets the current week of "go"

Source: Internet
Author: User

This article copy from: http://swxzqsd.blog.sohu.com/156208509.html

Camelcanoe

String today = "2010-01-11";
SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd");
Date date = Format.parse (today);
Calendar calendar = Calendar.getinstance ();
Calendar.setfirstdayofweek (Calendar.monday);
Calendar.settime (date);
System.out.println (Calendar.get (calendar.week_of_year));

A somewhat complex code was used to determine the date of the week of the year. Look at the Calendar class, see the Week_of_year, very practical. But there was a little bit of a problem, such as 2010-01-03, when the result was 2 (two weeks in 2010), because the United States was the first day of the week in Sunday.

I thought of it. Change the starting day of the week, Setfirstdayofweek (int value), passing a 1, want to set Monday as the first day, but did not play an effect. After the document is changed into a calendar.monday, but it is not clear why the use of 1, with Calendar.monday on the line?

Fill: And look at the "constant field value", found that the value of Monday is not taken for granted at all 1, but 2.

Sunday:1

Mondya:2

Tuesday:3

Wednesday:4

Thursday:5

Friday:6

Saturday:7

Java gets the current week of "go"

Related Article

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.