스레드를 사용하여 타이밍 메커니즘을 만들려고하고 있는데 두 날짜 사이의 시간차가 생기고 그 차이를 사용하여 현재 비율을 얻는 데 문제가 있습니다. 남은 시간. 여기 개념은 내가 프로토 타입을 시도하고있다 : 여기두 날짜의 차이와 현재 시간의 백분율 java
그리고 나의 구현 :
long startMilisecs = System.currentTimeMillis();
long currentMilisecs;
long endDateMilisecs = getEndDate().getTime();
int diffMillisecs = ((int)(endDateMilisecs - startMilisecs)/1000)/60;
int currPerc;
while (startMilisecs <= endDateMilisecs)
{
currentMilisecs = (int) System.currentTimeMillis();
currPerc = ((int)currentMilisecs * 100)/diffMillisecs;
System.out.println(" Current Percentage: " + currPerc);
}
이 코드의 문제는 비율이 아니라 0부터 시작되지 않는 것입니다 20 ~ 40 %.
이 문제가 무엇이 있는지 알려주실 수 있습니까? 이 문제는 스레드 만 사용하도록 제한되었습니다.
당신이 비율을 의미합니까 무엇부터 시작되지 않은 0 – Woot4Moo
startMilisecs = System.currentTimeMillis는()이 완벽하게 작동 – BlackJoker