private void testChronology() { out.printf("--------------------- Test Chronology ---------------------------\n"); birthDays .entrySet() .forEach( e -> { JapaneseDate japaneseDate = JapaneseDate.from(stringToTime(e.getValue())); out.printf("%s was born %s.\n", e.getKey(), japaneseDate); }); }
private static void useLocalDate() { LocalDate date = LocalDate.of(2014, 3, 18); int year = date.getYear(); // 2014 Month month = date.getMonth(); // MARCH int day = date.getDayOfMonth(); // 18 DayOfWeek dow = date.getDayOfWeek(); // TUESDAY int len = date.lengthOfMonth(); // 31 (days in March) boolean leap = date.isLeapYear(); // false (not a leap year) System.out.println(date); int y = date.get(ChronoField.YEAR); int m = date.get(ChronoField.MONTH_OF_YEAR); int d = date.get(ChronoField.DAY_OF_MONTH); LocalTime time = LocalTime.of(13, 45, 20); // 13:45:20 int hour = time.getHour(); // 13 int minute = time.getMinute(); // 45 int second = time.getSecond(); // 20 System.out.println(time); LocalDateTime dt1 = LocalDateTime.of(2014, Month.MARCH, 18, 13, 45, 20); // 2014-03-18T13:45 LocalDateTime dt2 = LocalDateTime.of(date, time); LocalDateTime dt3 = date.atTime(13, 45, 20); LocalDateTime dt4 = date.atTime(time); LocalDateTime dt5 = time.atDate(date); System.out.println(dt1); LocalDate date1 = dt1.toLocalDate(); System.out.println(date1); LocalTime time1 = dt1.toLocalTime(); System.out.println(time1); Instant instant = Instant.ofEpochSecond(44 * 365 * 86400); Instant now = Instant.now(); Duration d1 = Duration.between(LocalTime.of(13, 45, 10), time); Duration d2 = Duration.between(instant, now); System.out.println(d1.getSeconds()); System.out.println(d2.getSeconds()); Duration threeMinutes = Duration.of(3, ChronoUnit.MINUTES); System.out.println(threeMinutes); JapaneseDate japaneseDate = JapaneseDate.from(date); System.out.println(japaneseDate); }