2014-11-27 2 views
-1

공용 클래스 ShowCurrentTimesystem.currentTimeMillis()를 사용하여 시간대의 현재 시간을 추출하는 방법은 무엇입니까?

{

공공 정적 무효 메인 (문자열 []에 args)

{ 

// Obtain the total milliseconds 

long totalMilliseconds = System.currentTimeMillis(); 

// Obtain the total seconds 

long totalSeconds = totalMilliseconds/1000; 

// Compute the current second in the minute in the hour 

long currentSecond = totalSeconds % 60; 

// Obtain the total minutes 

long totalMinutes = totalSeconds/60; 

// Compute the current minute in the hour 

long currentMinute = (totalMinutes % 60); 

// Obtain the total hours 

long totalHours = totalMinutes/60; 

// Compute the current hour 

long currentHour = totalHours % 24; 

// Display results 

System.out.println("Current time is " + currentHour + ":" + currentMinute + ":" + currentSecond + "GMT"); 

} 

}


이 코드를 실행, 그리니치 표준시가 부여하는 방법을 구성합니다 GMT +5 : 30 (IST)와 같은 특정 시간대의 현재 시간을 얻으려고합니까?

답변

0

번 (Java가 UTC 인 경우) 다른 시간대에 표시해야하는 경우 Calendar 클래스를 사용하고 원하는 시간대를 설정할 수 있습니다.

관련 문제