Java dos只輸出一行,單行重新整理案例,單行動態列印
阿新 • • 發佈:2021-01-30
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateDemo{
public static void main(String[] args) throws InterruptedException {
Date d;
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String stime;
while (true){
d=new Date();
long time = d.getTime();
Thread.sleep(1000);
stime =sdf.format(time);
System.out.print(stime+"\r");
}
}
}
主要是這一句
System.out.print(stime+"\r");
兩個要點
- .println去掉ln
- 末尾加上"\r"
實現效果,時間是單行動態重新整理的。