最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Java中的new Date所得的年份异常:传入2043年结果却是3943年

Java crifan 2457浏览 0评论

【问题】

折腾:

【暂未解决】Eclipse中调试Java代码期间如何修改值

期间,就发现一个现象:

在用:

Date newExpiryDate = new Date(2043, 9, 17);

结果却得到一个3943年的结果:

 

如图:

 

2043 year become to 3943 year

 

很是诡异。

【折腾过程】

1.后来的后来,算是去参考:

Class java.util.Date

看到:

  public Date(int year,
              int month,
              int date)
Creates a date. The fields are normalized before the Date object is created. The arguments do not have to be in the correct range. For example, the 32nd of January is correctly interpreted as the 1st of February. You can use this to figure out what day a particular date falls on.

Parameters:
year – a year after 1900
month – a month between 0-11
date – day of the month between 1-31

才知道:

原来传入的年份,会自动加上1900

所以:

传入2043

结果变成:

2043+1900=3943

 

【总结】

java中的Date中的year的设计,简单说就是:

你妹的!

十分的坑爹型的。

和人类思维不一样。

转载请注明:在路上 » 【已解决】Java中的new Date所得的年份异常:传入2043年结果却是3943年

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.169 seconds, using 22.14MB memory