New Date & Time API in Java 8

前端 未结 2 1657
滥情空心
滥情空心 2021-02-13 22:51

On this page i read the following:

To do calculations with dates, it is also very easy. Probably the best improvement compared to the current situation with Java < 1.

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-13 23:34

    Advantages of the new date/time API

    • The notions of date (LocalDate), time (LocalTime), date&time (LocalDateTime), instant (Instant) are much clearer and correspond to their meaning in common language.
    • Intializing date/time to a specific value got easier (method 'of', e.g. LocalDate.of(2016,1,1))
    • Dealing with leap years (method isLeapYear) got trivial
    • Adding/subtracting dates got very easy. E.g. to reference today in 10 years: LocalDate.now().plusYears(10)
    • Month numbering offset adapted to intuition. 'January' is '1' now and not '0' as before

    Disadvantages

    • Not yet supported by JPA2
    • Not yet supported by JSF2

提交回复
热议问题