主要方法:
Date date = new Date(System.currentTimeMillis());//获取系统当前时间
new SimpleDateFormat("HH:mm:ss").format(date)//更改系统时间的格式
import java.text.SimpleDateFormat;
import java.util.Date;
public class MyThreadSleep {
public static void main(String[] args) throws InterruptedException {
Date date = new Date(System.currentTimeMillis());//获取系统当前时间
while(true){
Thread.sleep(1000);
//输出当前时间
System.out.println(new SimpleDateFormat("HH:mm:ss").format(date));
//更新时间
date = new Date(System.currentTimeMillis());
}
}
}
结果:
10:53:42
10:53:43
10:53:44
10:53:45
10:53:46
10:53:47