2013-10-03 47 views
0
String callTime = secondsToDisplayableString(log.getCallDuration()); 
String callDate = String.valueOf(log.getTimestamp()); 

private String secondsToDisplayableString(int secs) { 

    SimpleDateFormat data = new SimpleDateFormat("HH:mm:ss"); 

    Calendar cal = Calendar.getInstance(); 

    cal.set(0, 0, 0, 0, 0, secs); 

    return data.format(cal.getTime()); 

}` 

我的輸出是sec。我想轉換爲hh.mm.ss。我的代碼使用timestamp date and time。請告訴我如何可以轉換轉換輸出秒HH.MM.SS格式的Android

回答

0

試試這個

public static int[] splitToComponentTimes(BigDecimal yousecoutput) 
{ 
    long longVal = yousecoutput.longValue(); 
    int hours = (int) longVal/3600; 
    int remainder = (int) longVal - hours * 3600; 
    int mins = remainder/60; 
    remainder = remainder - mins * 60; 
    int secs = remainder; 

    int[] ints = {hours , mins , secs}; 
    return ints; 
} 
0

寫自己的算法中這樣

s = (ms/1000) % 60; 
m = (ms/(1000 * 60)) % 60; 
h = (ms/(1000 * 60 * 60)) % 24; 

,並在結尾處加上日如你所願。

相關問題