> 文档中心 > 线程十一——模拟当前系统时间倒计时

线程十一——模拟当前系统时间倒计时

注意: 这里用到SimpleDateFormat类对时间进行格式化

package com.yyf.ThreadSleep;import java.text.SimpleDateFormat;import java.util.Date;// 模拟倒计时public class TestSleep3{    public static void main(String[] args) {    //   模拟打印系统当前时间 Date startTime = new Date (System.currentTimeMillis ()); do {     try {  Thread.sleep (1000);  System.out.println (new SimpleDateFormat ("HH:mm:ss").format (startTime));  startTime = new Date (System.currentTimeMillis ());     } catch (InterruptedException e) {  e.printStackTrace ();     } } while (true);    }}

13:42:15
13:42:16
13:42:17
13:42:18
13:42:19
13:42:20
13:42:21