Why does Java's java.time.format.DateTimeFormatter#format(LocalDateTime) add a year?

前端 未结 1 675
旧巷少年郎
旧巷少年郎 2020-12-04 01:35

This is the code:

LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(1451438792953L), ZoneId.of(\"UTC\"));
DateTimeFormatter dateTime         


        
相关标签:
1条回答
  • 2020-12-04 01:40

    From Wikipedia:

    [YYYY] indicates the ISO week-numbering year which is slightly different from the traditional Gregorian calendar year (see below).

    1. YYYY is an ISO-8601 style representation of the year.
    2. yyyy is the Gregorian year-of-era representation.

    Since the the calculation of the two can be different by +1 or -1, hence the formatting. More useful info at YEAR_OF_ERA, YEAR, and weekBasedYear.

    0 讨论(0)
提交回复
热议问题