【问题标题】:convert output sec to hh.mm.ss format in android [duplicate]在android中将输出秒转换为hh.mm.ss格式[重复]
【发布时间】:2026-02-14 04:55:01
【问题描述】:
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。请告诉我如何转换

【问题讨论】:

    标签: android


    【解决方案1】:

    试试这个

    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;
    }
    

    【讨论】:

      【解决方案2】:

      这样写你自己的算法

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

      最后按照你的意愿添加它们。

      【讨论】:

        最近更新 更多