Why does Java#39;s java.time.format.DateTimeFormatter#format(LocalDateTime) add a year?(为什么Java的 java.time.format.DateTimeFormatter#format(LocalDateTime) 加一年?)
问题描述
这是代码:
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(1451438792953L), ZoneId.of("UTC"));
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("YYYY-MM-dd'T'HH:mm:ss.SSS'Z'");
String output = dateTimeFormatter.format(localDateTime);
这是localDateTime的值:
2015-12-30T01:26:32.953
这是输出的值:
2016-12-30T01:26:32.953Z
为什么要加一年?
在 java.time.temporal.WeekFields 中有几个带有 newYearWeek 的方法,这些方法有时将年份增加 1.为什么?
In java.time.temporal.WeekFields there are a couple of methods with a newYearWeek which increment the year by 1 on occasion. Why?
这是一个奇怪的错误.
推荐答案
来自 维基百科:
[YYYY] 表示 ISO 周编号年份,略不同于传统的公历年(见下文).
[YYYY] indicates the ISO week-numbering year which is slightly different from the traditional Gregorian calendar year (see below).
YYYY是年份的 ISO-8601 样式表示.yyyy是公历年份表示.
YYYYis an ISO-8601 style representation of the year.yyyyis the Gregorian year-of-era representation.
由于两者的计算可以相差+1或-1,因此格式.更多有用信息请参见 YEAR_OF_ERA, YEAR 和 weekBasedYear.
Since the the calculation of the two can be different by +1 or -1, hence the formatting. More useful info at YEAR_OF_ERA, YEAR, and weekBasedYear.
这篇关于为什么Java的 java.time.format.DateTimeFormatter#format(LocalDateTime) 加一年?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么Java的 java.time.format.DateTimeFormatter#format(Lo
基础教程推荐
- 存储 20 位数字的数据类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
