import java.util.Date;
public class RunWhileLoopForNSeconds_Java {
public static void main(String[] args) throws InterruptedException {
long starttime = System.currentTimeMillis() / 1000;
long seconds = 3;
long endtime = starttime + seconds;
while (starttime < endtime) {
Thread.sleep(1000);
starttime = System.currentTimeMillis() / 1000;
System.out.println(new Date(starttime * 1000));
}
}
}
/*
run:
Fri Oct 11 07:26:45 GMT 2024
Fri Oct 11 07:26:46 GMT 2024
Fri Oct 11 07:26:47 GMT 2024
*/