毫秒转换为基本时间 [英] Milliseconds conversion to basic time

查看:44
本文介绍了毫秒转换为基本时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 1774132 转换为 30:42 或 30 分 42 秒或任何输出.有没有 PHP 函数可以做到这一点?

I need to convert 1774132 to 30:42 or 30 minutes and 42 seconds or whatever the output of this is. Is there any PHP function that does this?

推荐答案

我很久以前在网上发现这个,但我现在不知道从哪里来了:

I found this online a long time ago, but I have no idea where from anymore:

<?php

function secondsToWords($seconds)
{
    /*** return value ***/
    $ret = "";

    /*** get the hours ***/
    $hours = intval(intval($seconds) / 3600);
    if($hours > 0)
    {
        $ret .= "$hours hours ";
    }
    /*** get the minutes ***/
    $minutes = bcmod((intval($seconds) / 60),60);
    if($hours > 0 || $minutes > 0)
    {
        $ret .= "$minutes minutes ";
    }

    /*** get the seconds ***/
    $seconds = bcmod(intval($seconds),60);
    $ret .= "$seconds seconds";

    return $ret;
}

echo secondsToWords(time());
?>

这篇关于毫秒转换为基本时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆