怎样将秒数转换成 小时:分钟的格式

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

原文地址:https://www.cnblogs.com/web-record/p/11124711.html

时间: 2024-08-01 13:56:41

怎样将秒数转换成 小时:分钟的格式的相关文章

将秒数转换成 hh:mm:ss 格式的方法

private function getTimeFormat(second:uint):String { var hh:Number = (second/3600)>>0;//把秒除得时间 var mm:Number = (second%3600)/60>>0;//把余数用于除得分钟 var ss:Number = (second%3600)%60>>0;//最后的余数直接就是秒钟 var tss:String = ss<10 ? "0"+ss

PHP 将秒数转换成时分秒

将秒数转换成时分秒,PHP提供了一个函数gmstrftime,不过该函数仅限于24小时内的秒数转换.对于超过24小时的秒数,我们应该怎么让其显示出来呢,例如 34:02:02 $seconds = 3600*34+122; function changeTimeType($seconds){ if ($seconds>3600){ $hours = intval($seconds/3600); $time = $hours.":".gmstrftime('%M:%S', $sec

微信小程序中利用时间选择器和js无计算实现定时器(将字符串或秒数转换成倒计时)

转载注明出处 今天写小程序,有一个需求就是用户选择时间,然后我这边就要开始倒计时. 因为小程序的限制,所以直接选用时间选择器作为选择定时器的小时和分钟.唯一的缺点就是不能选择秒. 一开始的想法是选择的到一个字符串以后,截取字符串转换成数字然后和以前一样不停的计算.什么计算秒数,换算成分数啊之类的 想想虽然不难但还是太麻烦了.就想有没有简单易懂的实现方法. 首先想到的就是js中的Date() 因为这个函数可以传字符串获取毫秒数,传毫秒数获取字符串.那么总体上来看,应该是可行的. 思路: 首先我们的

iOS 秒数转换成时间,时,分,秒

//转换成时分秒 - (NSString *)timeFormatted:(int)totalSeconds{ int seconds = totalSeconds % 60;     int minutes = (totalSeconds / 60) % 60;     int hours = totalSeconds / 3600; return [NSString stringWithFormat:@"%02d:%02d:%02d",hours, minutes, seconds

把秒数转换成时分秒

/** 转换时间格式 */ function changeTimeType($time) { if (is_numeric($time)) { $value = array( "days" => 0, "hours" => 0, "minutes" => 0, "seconds" => 0, ); if ($time >= 86400) { $value["days"] = f

把视频秒数转换成时间格式输出

function secondsToTime(time,forceHours){     var hours = Math.floor(time / 3600) % 24, minutes = Math.floor(time / 60) % 60, seconds = Math.floor(time % 60), result = ( (forceHours || hours > 0) ? (hours < 10 ? '0' + hours                           

PHP函数gmstrftime()将秒数转换成天时分秒

http://yangjunwei.com/a/930.html PHP函数gmstrftime()将秒数转换成天时分秒 一个应用场景需要用到倒计时的时分秒,比如新浪微博授权有效期剩余: 7天16小时47分钟42秒…… 在PHP环境下,PHP函数 gmstrftime() 可实现将秒数转换成时分秒的转换,先看例子: define("BJTIMESTAMP" , time()); //服务器当前时间 $expires_in = '1439577160';//到期时间 $expires =

C#- 将秒数转化成任意时间格式

将秒数转化成任意时间格式,可以使用C#的一个函数TimeSpan,看示例: TimeSpan ts = new TimeSpan(0, 0, 3661); richTextBox2.Text = ts.Hours + "小时" + ts.Minutes + "分钟" + ts.Seconds + "秒"; 也可以使用传统的方法,看示例:   int TotleTime=3661;//秒         int hour;         int

十进制的数转换成十六进制的数 (转)

#include<stdlib.h> #include<string.h> #include<stdio.h> /* * 方 法: decimal2Hex * 功 能:十进制的数转换成十六进制的数 * 参 数:int num : 十进制的数 * 返回值:char * : 十六进制的字符 */ char * decimal2Hex(int num){ int a[100]; int i=0; int m=0; int yushu; char hex[16]={'0','1