java 0000,在Java中的0000年

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值