Java 關於計算程式執行的時間差System類的public static long currentTimeMillis()方法
阿新 • • 發佈:2018-12-18
@[toc](Java 關於計算程式執行的時間差System類的public static long currentTimeMillis()方法)
1.java.lang.System類
- System類提供的public static long currentTimeMillis()用來返回當前時間與1970年1月1日0時0分0秒之間以毫秒為單位的時間差。
此方法用於計算時間差
public void test1() { long startTime = 0L; long endTime = 0L; StringBuffer buffer = new StringBuffer(""); //往StringBuffer物件裡面新增20000個字元,時間 startTime = System.currentTimeMillis(); for(int i = 0;i<20000;i++){ buffer.append(String.valueOf(i));} endTime = System.currentTimeMillis(); System.out.println("StringBuffer的執行時間:"+(endTime-startTime)); }
- 計算世界時間的主要標準有:
UTC(Universal Time Coordinated)
GMT(Greenwich Mean Time)
CST(Central Standard Time)