PHP 秒数 转时分秒 函数

function secondsToHour($seconds){
    if(intval($seconds) < 60)
        $tt ="00时00分".sprintf("%02d",intval($seconds%60));
    if(intval($seconds) >=60){
        $h =sprintf("%02d",intval($seconds/60));
        $s =sprintf("%02d",intval($seconds%60));
        if($s == 60){
            $s = sprintf("%02d",0);
            ++$h;
        }
        $t = "00";
        if($h == 60){
            $h = sprintf("%02d",0);
            ++$t;
        }
        if($t){
            $t  = sprintf("%02d",$t);
        }
        $tt= $t."时".$h."分".$s.‘秒‘;
    }
    if(intval($seconds)>=60*60){
        $t= sprintf("%02d",intval($seconds/3600));
        $h =sprintf("%02d",intval($seconds/60)-$t*60);
        $s =sprintf("%02d",intval($seconds%60));
        if($s == 60){
            $s = sprintf("%02d",0);
            ++$h;
        }
        if($h == 60){
            $h = sprintf("%02d",0);
            ++$t;
        }
        if($t){
            $t  = sprintf("%02d",$t);
        }
        $tt= $t."时".$h."分".$s.‘秒‘;
    }
   return  $seconds>0?$tt:‘00时00分00秒‘;
}
时间: 2024-08-30 08:35:45

PHP 秒数 转时分秒 函数的相关文章

php实现显示网站运行时间-秒转换年月日时分秒

<?php // 设置时区 date_default_timezone_set('Asia/Shanghai'); /** * 秒转时间,格式 年 月 日 时 分 秒 * * @author [email protected] * @param int $time * @return array|boolean */ function Sec2Time($time){ if(is_numeric($time)){ $value = array( "years" => 0,

Oracle 把秒转成时分秒格式(呵呵4)

1 CREATE OR REPLACE FUNCTION to_time(sec IN NUMBER) RETURN VARCHAR2 IS 2 /*把秒转成时分秒格式 3 auth lzpong 201/09/16 4 */ 5 BEGIN 6 RETURN TRUNC(NVL(sec,0)/3600)||':'||SUBSTR(NUMTODSINTERVAL(NVL(sec,0), 'second'),15,5); 7 EXCEPTION WHEN OTHERS THEN RETURN '0

Oracle 把秒转成时分秒格式(hh24:mm:ss);检测字符串是否是数字

不说废话,贴代码: 1 CREATE OR REPLACE FUNCTION to_time(sec IN NUMBER) RETURN VARCHAR2 IS 2 /*把秒转成时分秒格式 3 auth lzpong 201/09/16 4 */ 5 BEGIN 6 RETURN TRUNC(NVL(sec,0)/3600)||':'||SUBSTR(NUMTODSINTERVAL(NVL(sec,0), 'second'),15,5); 7 EXCEPTION WHEN OTHERS THEN

将秒数转换为时分秒的形式java形式

将一个秒数转换为时分秒形式,例如91秒=00:01:31 public class Main { public static void main(String[] args) { System.out.println(transfom(3665)); } public static String transfom(final int time) { int hh = time / 3600; int mm = (time % 3600) / 60; int ss = (time % 3600)

秒转为日时分秒(00:00:00:00格式)

日志记录job执行耗时, 格式为00:00:00:00, 例如:00:23:15:00, 代表执行了23小时15分钟. 工具类写了个方法: /** * @Author: liangyadong * @Date: 2019/3/21 0021 下午 2:33 * @Description: 返回日时分秒 格式:days:HI24:mm:ss 小时为24小时制 */ public static String secondToTime(long seconds) { long days = secon

JS秒数转成分秒时间格式

源于:http://www.huiyi8.com/jiaoben/ flash特效 // 格式化秒数到时间格式 Number.prototype.formatTime=function(){     // 计算     var h=0,i=0,s=parseInt(this);     if(s>60){         i=parseInt(s/60);         s=parseInt(s%60);         if(i > 60) {             h=parseInt

毫秒数变成时分秒倒计时

js抽象代码: ;(function($){ /**时间间隔对象 * @author Karajan * @param gap 间隔毫秒 * @param {cT:当前时间(毫秒),eT:截止时间(毫秒),gap:间隔(毫秒),aEven:到点触发的事件function,iEven:初始化函数,初始化时被调用,lEven:倒计时结束触发方法} * */ function dateGap(gap){ var di=[],dCt=[1000*60*60*24,1000*60*60,1000*60,1

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

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

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