Home > php教程 > PHP源码 > php time and date calculation

php time and date calculation

大家讲道理
Release: 2016-11-08 11:09:00
Original
1924 people have browsed it

//时间计算 开始,结束,类型
function shijianjisuan($kaishi,$jieshu,$leixing='shi') {
    if ($leixing=='shi')//小时
    {
    $sc = floor((strtotime($jieshu) - strtotime($kaishi)) / 3600);
    }
    elseif ($leixing=='fen')//分钟
    {
    $sc = floor((strtotime($jieshu) - strtotime($kaishi)) / 60);
    }
    elseif ($leixing=='tian')//天
    {
       $sc = floor((strtotime($jieshu) - strtotime($kaishi)) / 3600/24); 
    }
    return $sc;
}
 
$a='2016-08-02';
$b='2016-08-04';
echo shijianjisuan($a,$b,'tian');
Copy after login

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template