输出以秒为单位.在php中转换为hh:mm:ss格式 [英] Output is in seconds. convert to hh:mm:ss format in php

查看:111
本文介绍了输出以秒为单位.在php中转换为hh:mm:ss格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 我的输出格式为290.52262423327秒.我如何将其更改为00:04:51?

  1. My output is in the format of 290.52262423327 seconds. How can i change this to 00:04:51?

我想以秒和HH:MM:SS格式显示相同的输出,所以如果是秒,我只想显示290.52秒.(小数点后仅两个整数)?我该怎么办?

The same output i want to show in seconds and in HH:MM:SS format, so if it is seconds, i want to show only 290.52 seconds.(only two integers after decimal point)? how can i do this?

我在php中工作,输出在$time变量中.想要将此H3:MM:SS的$time更改为$newtime,将$newsec更改为290.52.

I am working in php and the output is present in $time variable. want to change this $time into $newtime with HH:MM:SS and $newsec as 290.52.

谢谢:)

推荐答案

1)

function foo($seconds) {
  $t = round($seconds);
  return sprintf('%02d:%02d:%02d', ($t/3600),($t/60%60), $t%60);
}

echo foo('290.52262423327'), "\n";
echo foo('9290.52262423327'), "\n";
echo foo(86400+120+6), "\n";

打印

00:04:51
02:34:51
24:02:06

2)

echo round($time, 2);

这篇关于输出以秒为单位.在php中转换为hh:mm:ss格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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