在Java中的0000年 [英] Year 0000 in java

查看:172
本文介绍了在Java中的0000年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



请参见以下代码:

 字符串dateStr = 00000102; 
System.out.println(dateStr);
DateFormat dateFormat = new SimpleDateFormat( yyyyMMdd);
Date date = dateFormat.parse( 00000102);
字符串convertStr = dateFormat.format(date);
System.out.println(convertedStr);

输出如下:

  00000102 
00010102

有没有办法

解决方案

我不相信这是可能的,因为 java.util.Date 基于 UTC ,它基于格里高利历,而格里高利历没有零年。 (例如儒略历)没有年份0,而是在公元BC年使用序号1、2…。因此,传统的时间轴是2 BC,1 BC,AD 1和AD 2。


(来源:公历中的Wikipedia文章


When I parse a date with the year 0000 it appears to be stored as the year 0001.

See below for code:

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);

The output is as per below:

00000102
00010102

Is there a way to represent the year 0000 in Java using the standard Java API?

解决方案

I don't believe it's possible, since java.util.Date is based on UTC, which is based on the Gregorian calendar, and the Gregorian calendar has no year zero.

...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.

(Source: The Wikipedia article on the Gregorian calendar)

这篇关于在Java中的0000年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆