在android中将输出秒转换为hh.mm.ss格式

时间:2013-10-03 07:38:34

标签: android

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。请告诉我如何转换

2 个答案:

答案 0 :(得分: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;
}

答案 1 :(得分:0)

像这样编写自己的ALgo

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

并最终将它们作为您的愿望附加。