티스토리 뷰

package time;

import java.time.LocalTime;
import java.time.temporal.ChronoUnit;

public class LocalTime112 {
	public static void main(String[] args) {
		LocalTime now=LocalTime.of(6,30);
		long timeToBreakfast=0;
		LocalTime office_start=LocalTime.of(7,30);
		if(office_start.isAfter(now)) {
			timeToBreakfast=now.until(office_start, ChronoUnit.MINUTES);
		}else {
			timeToBreakfast=now.until(office_start, ChronoUnit.HOURS);
		}
		System.out.println(timeToBreakfast);
	}
}

Assume that the value of now is 6:30 in the morning.
What is the result?

출력:
60

해설:
6:30이 현재고(now) 7:30이 office_start이다.
if(office_start.isAfter(now)) 즉, office_start가 now보다 뒤냐고 하면 7:30이 6:30보다 뒤기 때문에 true이다.
timeToBreakfast=now.until(office_start, ChronoUnit.MINUTES); 에 의해 now와 office_start 시간 사이의 양을 분으로 계산하면 60이다.

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함