日期格式yyyy-MM-dd和YYYY-MM-dd有什么区别

之前有看到一篇文章,忘掉了,后来上网看了看,说的也不是很详细

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().

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

猜你喜欢

转载自www.cnblogs.com/jiuxu/p/12157041.html