@Test public void testBasic() { System.out.println(Year.now()); System.out.println(Year.of(2015)); System.out.println(Year.isLeap(2016)); Locale locale = Locale.getDefault(); System.out.println(Month.DECEMBER.getDisplayName(TextStyle.FULL, locale)); System.out.println(Month.DECEMBER.getDisplayName(TextStyle.SHORT, locale)); System.out.println(Month.DECEMBER.getDisplayName(TextStyle.NARROW, locale)); System.out.println(Month.DECEMBER.getDisplayName(TextStyle.FULL_STANDALONE, locale)); System.out.println(Month.of(8).ordinal()); System.out.println(Month.AUGUST.minus(2)); System.out.println(YearMonth.now()); System.out.println(MonthDay.now()); System.out.println(DayOfWeek.FRIDAY.plus(2)); System.out.println(DayOfWeek.of(1)); System.out.println( DayOfWeek.from(LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()))); System.out.println(Period.between(Year.now().atDay(1), LocalDate.now())); System.out.println(ChronoUnit.DAYS.between(Year.now().atDay(1), LocalDate.now())); }
@Test public void testLocalDateTime() { System.out.println(LocalDateTime.now()); System.out.println(LocalDateTime.of(1994, Month.MAY, 15, 11, 30)); System.out.println(LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault())); System.out.println(LocalDateTime.ofEpochSecond(1450749600, 0, ZoneOffset.ofHours(8))); System.out.printf("6 months from now: %s%n", LocalDateTime.now().plusMonths(6)); System.out.printf("6 days ago: %s%n", LocalDateTime.now().minusDays(6)); System.out.println(DateTimeFormatter.ISO_DATE_TIME.format(LocalDateTime.now())); System.out.println(DateTimeFormatter.ofPattern("MM-dd HH:mm").format(LocalDateTime.now())); }
@Override public LocalDateTime convert(Date source) { return source == null ? null : LocalDateTime.ofInstant(source.toInstant(), ZoneId.systemDefault()); }