Http://blog.sina.com.cn/s/blog_45c06e600100pm77.html
——————————————————————————————————————————————————————————————————————
Online search, just contact Calendar class, a little complicated, write down.
The Calendar class is used for processing dates in Java, and there are several methods that need to be noticed by novice users.
1. Reason for Calendar.month + 1 when getting the month
the months in Java follow the rules in the Roman calendar: The number of months in a year is not fixed, and the first month is January. The value returned by Calendar.month in Java is actually the number of months from the first month of the current month, and January returns "0" in Java, so we need +1.
2. Reasons for the calendar.day_of_week–1 of the day of the week
In Java, Calendar.day_of_week actually says: The day of the week, so he will be affected by the days of the week .
Some regions take Sunday as the first day of the week, while some regions take Monday as the first day of the week, and these 2 cases need to be differentiated.
Look at the return value of the following table
| Sunday is the first day of the week |
SUN |
MON |
TUE |
WED |
THU |
FRI |
Sat |
| Day_of_week return value |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
| Monday is the first day of the week |
MON |
TUE |
WED |
THU |
FRI |
Sat |
SUN |
| Day_of_week return value |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
So calendar.day_of_week need to determine if "1" is required depending on the locale setting
Output from different locales in Java can be implemented using Locale.setdefault (locale. Region name).
3. Calendar.day_of_month does not require special action when getting the date, he returns the day of the one month directly
Why Calendar.day_of_week needs to be reduced in Java