2012-02-29 4 views
0

시간이 밀리 초 단위 인 숫자가 있습니다. 어떻게 표시합니까?Java : 시간 형식 정밀도

Hour:mm:ss:+ 2 or 3 decimals 
+3

봐 : http://docs.oracle.com/javase/6/docs/api/ java/text/SimpleDateFormat.html –

+0

[java 형식의 밀리 초를 시간 형식으로 변환] 가능한 복제본 (http://stackoverflow.com/questions/4142313/java-convert-milliseconds-to-time-format) –

답변

6

long timeInMillis = 
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS"); 
sdf.setTimeZone(TimeZone.getTimeZone("GMT")); 
String text = sdf.format(new Date(timeInMillis)); 

또는 문자열 자신

long timeInMillis = 3032; 
String text = String.format("%d:%02d:%02d.%03d", 
     timeInMillis/3600000, 
     timeInMillis/60000 % 60, 
     timeInMillis/1000 % 60, 
     timeInMillis % 1000); 
System.out.println(text); 

인쇄를 구축 할 수 있습니다

SimpleDateFormat의에서
0:00:03.032 
+0

date ???? 나는 시간을 mounths 및 일 의미하지 않았다. –

+0

"날짜"는 milli-second 해상도이며 밀리 초 단위로 기록된다. –

+0

내가 3032를 입력하면 출력은 01 : 00 : 03 : 032 ... 1은 어디에서 왔습니까 ?? –