之前有看到一篇文章,忘掉了,后來上網看了看,說的也不是很詳細
y是year,Y是week year,
YYYY-MM-dd里面大寫的YYYY會在每年的最后一周和最初的一周造成一些影響,
Week Of Year and Week Year
Values calculated for the WEEK_OF_YEAR
field range from 1 to 53. The first week of a calendar year is the earliest seven day period starting on getFirstDayOfWeek()
that contains at least getMinimalDaysInFirstWeek()
days from that year. It thus depends on the values of getMinimalDaysInFirstWeek()
, getFirstDayOfWeek()
, and the day of the week of January 1. Weeks between week 1 of one year and week 1 of the following year (exclusive) are numbered sequentially from 2 to 52 or 53 (except for year(s) involved in the Julian-Gregorian transition).
The getFirstDayOfWeek()
and getMinimalDaysInFirstWeek()
values are initialized using locale-dependent resources when constructing a GregorianCalendar
. The week determination is compatible with the ISO 8601 standard when getFirstDayOfWeek()
is MONDAY
and getMinimalDaysInFirstWeek()
is 4, which values are used in locales where the standard is preferred. These values can explicitly be set by calling setFirstDayOfWeek()
and setMinimalDaysInFirstWeek()
.
A week year is in sync with a WEEK_OF_YEAR
cycle. All weeks between the first and last weeks (inclusive) have the same week year value. Therefore, the first and last days of a week year may have different calendar year values.
For example, January 1, 1998 is a Thursday. If getFirstDayOfWeek()
is MONDAY
and getMinimalDaysInFirstWeek()
is 4 (ISO 8601 standard compatible setting), then week 1 of 1998 starts on December 29, 1997, and ends on January 4, 1998. The week year is 1998 for the last three days of calendar year 1997. If, however, getFirstDayOfWeek()
is SUNDAY
, then week 1 of 1998 starts on January 4, 1998, and ends on January 10, 1998; the first three days of 1998 then are part of week 53 of 1997 and their week year is 1997.
就看看這個例子吧,翻譯過來就是1998/1/1是星期四 如果getFirstDayOfWeek()獲取的是周一,getMinimalDaysInFirstWeek()獲取的是周四(IOS 8601兼容設置),這樣1998年的第一個星期開始於1997/12/29,結束於1998/1/4 .1998的weekyear,有三天是1997年的最后三天.
如果getFirstDayOfWeek獲取的是周日,那么1998的第一周開始於1998/1/4 ,結束於1998/1/10. 所以1998年最開始的三天就是1997年的第53周的一部分,他們的weekyear就是1997
所以我們在使用日期格式的時候,就使用yyyy-MM-dd