[자바 (JAVA)] 29. ChoronoUnit

귤's avatar
Feb 13, 2025
[자바 (JAVA)] 29. ChoronoUnit

1. ChronoUnit

💡
시간의 양을 특정 시간 단위로 측정하는 데 사용되는 API이다.

2. ChronoUnit을 사용하여 시간차 구하기

package ex08; import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; public class Chrono01 { public static void main(String[] args) { LocalDateTime writeTime = LocalDateTime.of(2025, 02, 11, 10, 3); LocalDateTime nowTime = LocalDateTime.now(); long daysBetween = ChronoUnit.DAYS.between(nowTime, writeTime); long minsBetween = ChronoUnit.MINUTES.between(nowTime, writeTime); System.out.println(daysBetween + "일전"); System.out.println(minsBetween + "분전"); } }
notion image
 
Share article

gyul