當前位置:編程學習大全網 - 編程軟體 - java中.currentTimeMillis的用法和含義

java中.currentTimeMillis的用法和含義

用法:

可以用法獲取當前時間的毫秒數,可以通過毫秒數進行時間比較,時間轉化以及時間格式化等。

public class SystemTime {

public static void main(String[] args) {

//定義當時運行的時間變量

Long time = System.currentTimeMillis();

//打印開始時間的毫秒數

System.out.println(time);

for(int i =0;i<10000;i++){

//什麽都不用做

}

System.out.println("for循環運行的所需要時間(毫秒數)"+(System.currentTimeMillis()-time));

System.out.println("for循環運行的所需要時間(秒)"+(System.currentTimeMillis()-time)/1000);

System.out.println("顯示當前時間:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()));

}

}

含義:

主要是返回以毫秒為單位的當前時間,值的粒度取決於不同的操作系統:

  • 上一篇:《隕石惡夢》最新txt全集下載
  • 下一篇:五軸編程要學多久?
  • copyright 2024編程學習大全網