Why does java.util.Date represent Year as “year-1900”?

前端 未结 2 872
臣服心动
臣服心动 2021-01-12 17:25

In java.util.Date:

 * In all methods of class Date that accept or return
 * year, month, date, hours, minutes, and seco         


        
2条回答
  •  天涯浪人
    2021-01-12 18:16

    Basically the original java.util.Date designers copied a lot from C. What you're seeing is the result of that - see the tm struct. So you should probably ask why that was designed to use the year 1900. I suspect the fundamental answer is "because we weren't very good at API design back when tm was designed." I'd contend that we're still not very good at API design when it comes to dates and times, because there are so many different use cases.

    This is just the API though, not the storage format inside java.util.Date. No less annoying, mind you.

提交回复
热议问题