format转换yyyy和YYYY,dd和DD的区别
区别
因为我在开发过程中难免会对日期格式进行转变,但是我对转变的格式一致没太注意导致了一些bug
yyyy和YYYY的区别
jDK6的SimpleDateFormat只有小“y”,没有大“Y”。JDK7开始引入了大“Y”,表示Week year。Week year意思是当天所在的周属于的年份,一周从周日开始,周六结束,只要本周跨年,那么这周就算入下一年。例如2020年12月31日,本周(2020年12月31日-2021年1月6日)本周跨年了。就进入了下一年。
If a week is split at the end of the year then it is assigned to the year in which more that half of the days of that week occur.
u year
y year-of-era
Y week-based-year
这就导致了 2020-12-31 这天时会显示 2021-12-31 号这样的情况
并且用YYYY把日期从String类型转变为Date时,永远得不到想要的日期
来自 https://www.v2ex.com/t/633650?p=1
DD和dd的区别
小写d是指月中的日号(1-31)
大写D是指全年天数(0-365)