Java---获取当前时间

package Demo;
import java.util.*;
import java.io.*;
public class loop {
    public static void main(String[] args) {
        try{//获取当前时间,以及sleep
            long start = System.currentTimeMillis();
            for (int i = 0; i<5; i++){
                Thread.sleep(1000);
                System.out.println(i);
            }
            long end = System.currentTimeMillis();
            long diff = (end - start)/1000;
            System.out.println("。。。。。"+diff);
        }catch (Exception e){
            e.printStackTrace();
            System.out.println(e);
        }

    }
}

 

posted @ 2021-03-08 19:48  朵朵奇fa  阅读(55)  评论(0编辑  收藏  举报