一、代码(希望一直打印当前的时间)
package DR3;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TestSleep1 {
public static void main(String[] args) {
while(true){
//System.out.println(i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//System.out.println(new Date());
Date now =new Date();
SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String str =sdf.format(now);
System.out.println(str);
}
}
}
二、输出结果(执行程序后,想让结束,截图右下角stop)
"C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.3\jbr\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.3\lib\idea_rt.jar=59424:C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.3\bin" -Dfil