把秒数转换成时分秒


/**

转换时间格式

*/

function changeTimeType($time) {

if (is_numeric($time)) {

$value = array(

"days" => 0, "hours" => 0,

"minutes" => 0, "seconds" => 0,

);

if ($time >= 86400) {

$value["days"] = floor($time / 86400);

$time = ($time % 86400);

}

if ($time >= 3600) {

$value["hours"] = floor($time / 3600);

$time = ($time % 3600);

}

if ($time >= 60) {

$value["minutes"] = floor($time / 60);

$time = ($time % 60);

}

$value["seconds"] = floor($time);

if(strlen($value["hours"])<2 && $value["days"]==0){

$value["hours"]="0".$value["hours"];

}else if(strlen($value["hours"])<2 && $value["days"]!=0){

$value["hours"]=$value["days"] * 24 + $value["hours"];

}else{

$value["hours"]=$value["days"] * 24 + $value["hours"];

}

if(strlen($value["minutes"])<2){

$value["minutes"]="0".$value["minutes"];

}

if(strlen($value["seconds"])<2){

$value["seconds"]="0".$value["seconds"];

}

//return (array) $value;

$t = $value["hours"] . ":" . $value["minutes"] . ":" . $value["seconds"];

Return $t;

} else {

return "00:00:00";

}

}

时间: 2024-08-04 05:27:09

把秒数转换成时分秒的相关文章

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

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

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

javascript把秒数转成时分秒显示

function transferTime(second) { if (Number(second) && second > 0) { second = parseInt(second) // 舍去秒数以后的小数位 } else { return '00:00:00' } // 计算时分秒 var h,m,s; s = second % 60 m = ((second - s) % 3600) / 60 h = parseInt(second / 3600) // 优化输出 func

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

C#实现毫秒转换成时分秒的方法

本文实例讲述了C#实现毫秒转换成时分秒的方法.分享给大家供大家参考.具体实现方法如下: public static String formatLongToTimeStr(Long l) { String str = ""; int hour = 0; int minute = 0; int second = 0; second = l.intValue() / 1000; if (second > 60) { minute = second / 60; second = seco

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

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

JAVA将秒的总和转换成时分秒的格式

public static void main(String[] args) { String str = "221"; int seconds = Integer.parseInt(str); int temp=0; StringBuffer sb=new StringBuffer(); temp = seconds/3600; sb.append((temp<10)?"0"+temp+":":""+temp+&quo

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

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                           

将秒数转换成 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