image.png

    1. package com.pln.state;
    2. import java.text.SimpleDateFormat;
    3. import java.util.Date;
    4. public class TestSleep {
    5. public static void main(String[] args) throws InterruptedException {
    6. // tenDown();
    7. //获取系统时间
    8. Date startTime = new Date(System.currentTimeMillis());
    9. while (true){
    10. Thread.sleep(1000);
    11. System.out.println(new SimpleDateFormat("HH:mm:ss").format(startTime));
    12. startTime = new Date(System.currentTimeMillis());//更新时间
    13. }
    14. }
    15. //倒计时
    16. public static void tenDown() throws InterruptedException {
    17. int num = 10;
    18. while ( true){
    19. Thread.sleep(1000);
    20. System.out.println(num--);
    21. if(num==0){
    22. break;
    23. }
    24. }
    25. }
    26. }