Java时间模式中"yy"和"YY"之间的差异 [英] Difference between 'yy' and 'YY' in Java Time Pattern

查看:62
本文介绍了Java时间模式中"yy"和"YY"之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自文档 SimpleDateTimePattern ,<代码> yy 应该与 YY 相同.

From document SimpleDateTimePattern, yy should be the same with YY.

今天是 2019年12月30日,现在我们今天的 YY 是今天的 20 yy 19 .Java时间模式中的 yy YY 有什么区别?

Today is Dec 30, 2019, now we get YY for today is 20, yy for today is 19. What's the difference between yy and YY in Java Time Pattern?

推荐答案

yy 是日历年,而 YY 是一周年.一个星期可以与日历年不同,具体取决于1月1日是哪一天.例如,请参见 ISO-8601周年.

yy is the calendar year, while YY is a week year. A week year can be different from the calendar year depending on which day the first of January falls. For example see ISO-8601 week year.

今天(2019年12月30日)就是一个很好的例子,日历年是2019年,但是周年是2020年,因为本周是2020年的第1周.所以 yy 将导致> 19 ,而 YY 会导致 20 .

Today (30 December 2019) is a good example, the calendar year is 2019, but the week year is 2020, because this week is week 1 of 2020. So yy will result in 19, while YY results in 20.

维基百科页面中每年第一周的定义:

The definition of the first week of a year from the wikipedia page:

第01周的ISO 8601定义是带有公历的一周今年的第一个星期四.以下定义基于自ISO周以来,本周的属性相互等效从星期一开始:

The ISO 8601 definition for week 01 is the week with the Gregorian year's first Thursday in it. The following definitions based on properties of this week are mutually equivalent, since the ISO week starts with Monday:

  • 这是第一周,一月的大部分时间(至少4天).
  • 第一天是距1月1日最近的星期一.
  • 它有1月4日.因此,最早的第一周可能从12月29日星期一(公历前一年)延长至4月星期日一月,最可能的第一周从一月4日星期一开始到1月10日星期日.
  • 如果周六,周日和1月1日不是工作日,则它具有一年中的第一个工作日.

如果1月1日是星期一,星期二,星期三或星期四,则位于第01周.如果1月1日是星期五,则它是该周的第53周的一部分前一年.如果是星期六,则是该周最后一周的一部分上一年,同一年份的编号为52,而普通年份的编号为53闰年.如果在星期日,则它是前一个星期的第52周的一部分年.

If 1 January is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01. If 1 January is on a Friday, it is part of week 53 of the previous year. If it is on a Saturday, it is part of the last week of the previous year which is numbered 52 in a common year and 53 in a leap year. If it is on a Sunday, it is part of week 52 of the previous year.

某些语言环境(例如美国)不遵循ISO-8601,因为它们将星期日作为一周的第一天,但​​是对于星期年份,它们具有类似的规则.

Some locales, like for example the US, don't follow ISO-8601, because there they use Sunday as the first day of the week, but they have similar rules for week years.

这篇关于Java时间模式中"yy"和"YY"之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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