gpt4 book ai didi

java - Java时间模式中 'yy'和 'YY'之间的区别

转载 作者:行者123 更新时间:2023-12-02 10:51:01 24 4
gpt4 key购买 nike

来自文档SimpleDateTimePattern , yy应该与 YY 相同.

今天是Dec 30, 2019 ,现在我们得到YY今天是 20 , yy今天是 19yy 和有什么不一样?和YY在Java时间模式中?

最佳答案

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

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

一年第一周的定义来自 wikipedia page :

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:

  • It is the first week with a majority (4 or more) of its days in January.
  • Its first day is the Monday nearest to 1 January.
  • It has 4 January in it. Hence the earliest possible first week extends from Monday 29 December (previous Gregorian year) to Sunday 4 January, the latest possible first week extends from Monday 4 January to Sunday 10 January.
  • It has the year's first working day in it, if Saturdays, Sundays and 1 January are not working days.

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,因为他们使用星期日作为一周的第一天,但​​对于周年有类似的规则。

关于java - Java时间模式中 'yy'和 'YY'之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59527605/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com