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

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

问题描述

来自文档 SimpleDateTimePatternyy 应该与 YY 相同.

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

今天是Dec 30, 2019,现在我们得到YY今天是20yy19.Java 时间模式中的 yyYY 有什么区别?

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 日最近的星期一.
  • 其中包含 1 月 4 日.因此,最早可能的第一周从 12 月 29 日星期一(前公历年)延长到星期日 4一月,最晚的第一周从 1 月 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天全站免登陆