java.time 的纪年方式

        Date date = new Date();
        Instant instant = date.toInstant();
        Chronology chronology = HijrahChronology.INSTANCE;
        //Chronology chronology = IsoChronology.INSTANCE;
        ChronoZonedDateTime<? extends ChronoLocalDate> c = chronology.zonedDateTime(instant.atZone(ZoneId.systemDefault()));
        System.out.println(c);
        System.out.println(c.get(ChronoField.DAY_OF_YEAR));
        System.out.println(c.get(ChronoField.DAY_OF_MONTH));
        System.out.println(c.get(ChronoField.DAY_OF_WEEK));
        System.out.println(c.toLocalDateTime());

这里的 LocalDateTime 并不是 java.time.LocalDateTime。

作为 TemporalAccessor 可以得到很多想要的字段。

posted @ 2020-05-12 18:06  Inshua  阅读(180)  评论(0编辑  收藏  举报