Home > Backend Development > PHP Tutorial > Time and date conversion in php_PHP tutorial

Time and date conversion in php_PHP tutorial

WBOY
Release: 2016-07-13 16:55:51
Original
953 people have browsed it

This article introduces a custom time and date conversion function in PHP, which can convert events represented by seconds into time formats such as year, month, day, hour, etc.

 代码如下 复制代码

function Sec2Time($time){
if(is_numeric($time)){
$value = array(
"years" => 0, "days" => 0, "hours" => 0,
"minutes" => 0, "seconds" => 0,
);
if($time >= 31556926){
$value["years"] = floor($time/31556926);
$time = ($time%31556926);
}
if($time >= 86400){
$value["days"] = floor($time/86400);
$time = ($time%86400);
}
if($time >= 3600){
$value["hours"] = floor($time/3600);
$time = ($time%3600);
}
if($time >= 60){
$value["minutes"] = floor($time/60);
$time = ($time%60);
}
$value["seconds"] = floor($time);
return (array) $value;
}else{
return (bool) FALSE;
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631653.htmlTechArticleThis article introduces a custom function for time and date conversion in php, which can realize events that represent seconds Convert to year, month, day, hour and other time formats. The code is as follows Copy the code f...
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