주로 프로그램 실행 소요 시간을 구할 때 이용된다.
public class SystemTimeExample {
public static void main(String[] args) {
// 1970.1.1 0:00:00~ 현재시점까지의 기록된 시간을 밀리세컨드 단위로 표시.
// long time = System.currentTimeMillis();
//System.out.println(time);
long time1 = System.nanoTime(); //작업전 시간체크
//작업내용.
int sum = 0;
for(int i=1; i<=1000000;i++) {
sum += i;
}
long time2 = System.nanoTime(); //작업후 시간체크
System.out.println("1~1000000까지의 합: " + sum);
System.out.println("계산소요시간: " + (time2-time1) + " 나노초가 소요되었습니다.");
}
}
'JAVA' 카테고리의 다른 글
String 문자추출(charAt()) 메소드 (0) | 2022.10.07 |
---|---|
System클래스 (getProperty) (0) | 2022.10.07 |
Object 클래스 객체복제 clone() (0) | 2022.10.07 |
Object 클래스 객체 해시코드(hashCode()) (0) | 2022.10.07 |
Object 클래스 equals메소드 (0) | 2022.10.07 |