tonykang22 / study

0 stars 0 forks source link

[The JAVA8] 섹션 5. Date & Time #19

Open tonykang22 opened 2 years ago

tonykang22 commented 2 years ago

섹션 5. Date & Time

Date와 Time 소개




예제







Period _ 인류용

public class Main {
    public static void main(String[] args) {
        LocalDate today = LocalDate.now();
        LocalDate nextYearBirthday = LocalDate.of(2021, Month.NOVEMBER, 30);

        Period period = Period.between(today, nextYearBirthday);

        Period until = today.until(nextYearBirthday);

        long days = ChronoUnit.DAYS.between(today, nextYearBirthday);
        System.out.println(days);
    }
}



Duration _ 머신용

public class Main {
    public static void main(String[] args) {
        Instant now = Instant.now();
        Instant plus = now.plus(10, ChronoUnit.SECONDS);
        Duration between = Duration.between(now, plus);
        System.out.println(between.getSeconds());
    }
}