String time1 = br.readLine();
DateFormat sdf = new SimpleDateFormat("hh:mm:ss",Locale.ENGLISH);
Date d1 = sdf.parse(time1);
int n = Integer.parseInt(br.readLine());
for(int i=0;i<n;i++) {
String time2 = br.readLine();
Date d2 = sdf.parse(time2);
long diffMs = d1.getTime() - d2.getTime();
System.out.println(diffMs/(1000*60*60));
는 입력 :자바
time1 = 23:05:38
time2 = 12:36:07
출력이 10해야하지만 22을주고있다.
'hh'는 12 시간 형식이고, 'HH'는 24 시간 형식입니다. 나는 그것이 당신 문제라고 생각합니다. –
[자바에서 두 날짜 간의 차이 지속 시간을 찾는 방법] (https://stackoverflow.com/questions/17940200/how-to-find-the-duration-of-difference-between-two- dates-in-java) –
사이드 노트와 마찬가지로 LocalTime과 Duration을 사용하면 훨씬 쉬울 것입니다. – Deb