In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to use php to convert seconds into hours and seconds". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Php converts the number of seconds into hours and seconds: 1, create a PHP sample file; 2, create "function secondChanage ($second = 0) {...}" method to convert the number of seconds into hours and seconds.
This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer
The method of converting php seconds to hours, minutes and seconds:
Preface
One method that needs to be used for communication records is to convert seconds into minutes and seconds.
Method
PHP has a built-in method that can be used directly, but this is only within 24 hours. It's enough for the address book.
Example
$v = 30 position gmdate ('Hlav ipura slots, $v); / / 00:00:30
If you want to change to XX xx minutes XX seconds this format only needs to be converted, I directly use ternary nesting here
/ * *
* processing time
*
* @ param string $s conversion time
*
* @ return string $ftime processing time * /
Public function ftime ($s)
{
$time = explode (':', $s)
$time ['0'] = = '00'? $h = 0: $h = $time [' 0']
$time ['1'] = = '00'? $m = 0: $m = $time [' 1']
$time ['2'] = '00'? $s = 0: $s = $time [' 2']
$ftime = (
Empty ($h)?
Empty ($m)? $s. Second': (
Empty ($s)? $m. 'points': $m. 'points'. $s.' Seconds'
)
): (
Empty ($m) & & empty ($s)? $h. Hour': (
Empty ($m)? $h. The hour. $s. 'seconds': (
Empty ($s)? $h. 'hour'. $m. 'points': $h. 'hour'. $m. 'point'. $s. 'seconds'
)
)
)
); return $ftime
}
Effect picture
Recommended study: "PHP Video tutorial"
But this is only within 24 hours, although it is enough for the address book, but what if you need a display day next time? So let's rewrite a method.
/ * *
* convert seconds to days, hours, minutes
*
* @ param int $second timestamp
*
* @ return string * /
Function secondChanage ($second = 0)
{
$newtime =''
$d = floor ($second / (3600 / 24))
$h = floor (($second% (3600mm 24)) / 3600)
M = floor (($second% (3600mm 24))% 3600) / 60)
$s = $second-($dumb2403600)-($html 3600)-($massif 60); empty ($d)?
$newtime = (
Empty ($h)?
Empty ($m) $s. 'seconds': (
Empty ($s)? $m.' Points': $m.' Points'.$ s.' Seconds'
)
): (
Empty ($m) & empty ($s)? $h. 'Shi': (
Empty ($m)? $h. The hour. $s. 'seconds': (
Empty ($s)? $h. The hour. $m. 'points': $h. The hour. $m. 'points'. $s. 'seconds'
)
)
)
): $newtime =
Empty ($h) & & empty ($m) & & empty ($s) $d. 'Heaven': (
Empty ($h) & & empty ($m)? $d. 'God'. $s.' Second': (
Empty ($h) & & empty ($s)? $d. 'God'. $m.' Points': (
Empty ($m) & & empty ($s)? $d. 'God'. $h. 'Shi': (
Empty ($h)? $d. 'God'. $m. 'points'. $s.' Second': (
Empty ($m)? $d. 'God'. $h. The hour. $s.' Second': (
Empty ($s)? $d. 'God'. $h. The hour. $m.' Points': $d. 'God'. $h. The hour. $m.' Divide'. $s. 'seconds'
)
)
)
)
)
)
);
Return $newtime
}
This is the end of the content of "how to convert seconds into hours and seconds with php". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.