문제

I have a program that I would like to run at 9:00 PM my computer time. I need a way to find the milliseconds of that so that I can make the computer loop until it hits it. Something like this:

while(true){
    if(System.currentTimeMillis() == [insert method to find millis].[get](2100)){
         break;
    }
}
// Do stuff

So I just need a way to get those Millis from 9 PM. Any ideas?

도움이 되었습니까?

해결책

Create a new Calendar object (GregorianCalendar is most probable) and use getTimeInMillis().

Calendar cal = new GregorianCalendar(2013, 12, 18, 21, 0, 0);
if(System.currentTimeMillis() == cal.getTimeInMillis()){

}

It should be noted that if you want to do this regularly, you might want to look at a scheduled task instead.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top