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

前端 未结 2 900
臣服心动
臣服心动 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:01

    java.util.Date is no date at all. It is (quoting http://docs.oracle.com/javase/6/docs/api/java/util/Date.html) specific instant in time, with millisecond precision.

    It has no relationship with any particular date, hour, etc. You may extract day, year, etc from it- using given calendar and timezone. Diffrent calendars, timezones will give diffrent dates.

    If you are ever interested in storing date (day, month, year) do not use java.util.Date

    Instead

    • org.joda.time.DateTime from http://www.joda.org/joda-time/
    • if you are on java8, use java.time package http://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html

提交回复
热议问题