Y返回2012,而y在SimpleDateFormat中返回2011 [英] Y returns 2012 while y returns 2011 in SimpleDateFormat

查看:108
本文介绍了Y返回2012,而y在SimpleDateFormat中返回2011的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么'Y'返回2012,而'y'返回2011年$ SimpleDateFormat

I wonder why 'Y' returns 2012 while 'y' returns 2011 in SimpleDateFormat:

System.out.println(new SimpleDateFormat("Y").format(new Date())); // prints 2012
System.out.println(new SimpleDateFormat("y").format(new Date())); // prints 2011

可以解释为什么吗?

推荐答案

week year and year。来自javadoc

week year and year. From javadoc


一周与WEEK_OF_YEAR周期同步。在第一周和最后一周(含)之间的
之间的所有星期都具有相同的周年价值。
因此,一周的第一天和最后几天可能有不同的
日历年值。

例如1998年1月1日是星期四。如果getFirstDayOfWeek()是
MONDAY和getMinimalDaysInFirstWeek()是4(ISO 8601标准
兼容设置),那么1998年的第1周从1997年12月29日开始,
并于1月4日结束, 1998年,1997年为1997年的最后三个
日的一周,如果getFirstDayOfWeek()是
SUNDAY,那么1998年1月4日的第1周从1998年1月4日开始
1998年1月10日; 1998年的头三天是1997年的一年的b $ b 53,而他们的周年是1997年。

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.

这篇关于Y返回2012,而y在SimpleDateFormat中返回2011的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆