Home > Backend Development > PHP Tutorial > PHP method to implement formatting seconds based on custom function

PHP method to implement formatting seconds based on custom function

墨辰丷
Release: 2023-03-29 06:00:02
Original
1214 people have browsed it

This article mainly introduces the method of formatting seconds with PHP custom functions, involving the operation skills of PHP arrays and numerical operations. Friends in need can refer to it

The details are as follows:

function vtime($time) {
  $output = '';
  foreach (array(86400 => '天', 3600 => '小时', 60 => '分', 1 => '秒') as $key => $value) {
    if ($time >= $key) $output .= floor($time/$key) . $value;
    $time %= $key;
  }
  if($output==''){
    $output=0;
  }
  return $output;
}
//$now=time();
$oldtime=86465;
//echo vtime($now);//输出:17058天4小时8分55秒
echo vtime($oldtime);//输出:1天1分5秒
Copy after login

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

PHP method to implement two-dimensional array sorting by a certain column_phpTips

php Implementing Baidu weather forecast for WeChat development

PHP method to achieve batch acquisition of all fixed seed links in web pages

The above is the detailed content of PHP method to implement formatting seconds based on custom function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template