日期:2014-05-17  浏览次数:20878 次

怎样将秒数转换成 小时:分钟的格式
例如 3600秒就是 1:00 这种格式的 在jsp中转换也行,在java文件中转也行,在js中转也可以,望大侠赐教

------解决方案--------------------
JScript code
<script>
   /**  

   * @param {} second  

   * @return {}  

   * @desc 秒转化成dd hh:mm:ss  

   */ 

   function dateFormat(second){  

      var dd,hh,mm,ss;  

      second = typeof second === 'string' ? parseInt(second) : second;  

      if(!second || second < 0){  

          return;  

      }  

      //天  

      dd = second / (24 * 3600) | 0;  

      second = Math.round(second) - dd * 24 * 3600;  

      //小时  

      hh = second / 3600 | 0;  

      second = Math.round(second) - hh * 3600;  

      //分  

      mm = second / 60 | 0;  

      //秒  

      ss = Math.round(second) - mm * 60;  

      if(Math.round(dd) < 10){  

          dd = dd > 0 ? '0' + dd : '';  

      }  

      if(Math.round(hh) < 10){  

          hh = '0' + hh;  

      }  

      if(Math.round(mm) < 10){  

          mm = '0' + mm;  

      }  

      if(Math.round(ss) < 10){  

          ss = '0' + ss;  

      }  

      alert( dd + ' ' + hh + ':' + mm + ':' + ss);  

  }


</script>

------解决方案--------------------
Java code
int s,f,m;
        m=3600;
        s=m/3600; 
        f=m%3600/60;
        m=m%3600%60;

------解决方案--------------------
public class test2 
{
public static void main(String[] args){
double d=3600;
System.out.println("转换后的值:"+getNum(d).toString());
}

public static String getNum(double d){
double m=d/3600.00;
System.out.println(m);
String a[]=String.valueOf(m).split("\\.");
return a[0]+":"+a[1];
}
}
------解决方案--------------------
Java code

public static String second2date(long second){
        long time = -3600*8 + second;
        GregorianCalendar gc = new GregorianCalendar(); 
        gc.setTimeInMillis(time * 1000);
        String timestr = new SimpleDateFormat("HH:mm:ss").format(gc.getTime());
        return timestr;
    }

------解决方案--------------------
Java code

    public static String change(int seconds)
    {
        int temp=0;
        StringBuffer sb=new StringBuffer();
        sb.append(seconds/3600+":");

        temp=seconds%3600/60;
        sb.append((temp<10)?"0"+temp+":":""+temp+":");

        temp=seconds%3600%60;
        sb.append((temp<10)?"0"+temp:""+temp);

        return sb.toString();
    }