java - Java 中的 0000 年

标签 java date

当我解析 0000 年的日期时,它似乎存储为 0001 年。

代码见下:

String dateStr = "00000102";
System.out.println(dateStr);
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
Date date = dateFormat.parse("00000102");
String convertedStr = dateFormat.format(date);
System.out.println(convertedStr);

输出如下:
00000102
00010102

有没有办法使用标准 Java API 在 Java 中表示 0000 年?

最佳答案

我不相信这是可能的,因为 java.util.Date 基于 UTC ,这是基于 Gregorian calendar ,并且公历没有零年。

...the traditional proleptic Gregorian calendar (like the Julian calendar) does not have a year 0 and instead uses the ordinal numbers 1, 2, … both for years AD and BC. Thus the traditional time line is 2 BC, 1 BC, AD 1, and AD 2.



(来源:The Wikipedia article on the Gregorian calendar)

关于java - Java 中的 0000 年,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8440480/

相关文章:

java - 是否有处理有效数字的 Java 数字格式化库?

java - Android Studio 增量内存使用

javascript - AngularJS 日期过滤器 firefox/safari 问题

python - 在 Pandas 中添加日期

date - unix_timestamp 函数在 Hive 中将 2 位格式年份转换为 4 位格式年份的逻辑是什么?

excel - 确定字符串是否是某个范围内的日期前缀的算法

Java贷款计算器不正确

java - 我应该将 REST 资源放置在动态 Web 应用程序中的哪个文件夹中?

java - SimpleDateFormat 没有按预期工作

java - 如何在 Eclipse(Java 项目)中启用内存监视器?