java 年份和基于周的年份之间的区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26431882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between year-of-era and week-based-year?
提问by Brian
Java 8's DateTimeFormatterclass has a method, ofPattern(String pattern), that lets you define a format from a string of A-z, a-zletters. The examples don't clarify the difference between y, year-of-eraand Y, week-based-year. What is it?
Java 8 的DateTimeFormatter类有一个方法 ,ofPattern(String pattern)可以让您从A-z,a-z字母字符串定义格式。这些示例没有阐明y, year-of-era和Y, week-based-year之间的区别。它是什么?
Symbol Meaning Presentation Examples
------ ------- ------------ -------
y year-of-era year 2004; 04
Y week-based-year year 1996; 96
回答by hslugs
That's year value for "year-week" style dates, as in 2006W52. It may be off the year-of-era value by +1 or -1 if the week in question straddles year boundary.
这是“年-周”样式日期的年份值,如 2006W52。如果所讨论的周跨越年份边界,则它可能与时代值相差 +1 或 -1。
回答by JodaStephen
Each field is documented in a "field" class, such as ChronoField, WeekFieldsor IsoFields.
每个字段都记录在“字段”类中,例如ChronoField,WeekFields或IsoFields。
The "year-of-era" field is documented in ChronoField.
“年代”字段记录在ChronoField.
The "week-based-year" field is documented in WeekFields.
“基于周的年”字段记录在WeekFields.
回答by Sam Berry
week based year
基于周的年
A concept where a week only belongs to 1 year. For example:
一周只属于一年的概念。例如:
LocalDate.parse("2019-12-29").format(DateTimeFormatter.ofPattern("M/d/Y"))
---> "12/29/2020"`
year of era
年代
The common use of year, 1/1 always being the first day of the year. For example:
年的常见用法,1/1 总是一年的第一天。例如:
LocalDate.parse("2019-12-29").format(DateTimeFormatter.ofPattern("M/d/y"))
---> "12/29/2019"

