Home > php教程 > PHP源码 > body text

date_diff 计算"操作时间"与"当前时间" 的间隔

PHP中文网
Release: 2016-05-25 17:10:44
Original
1565 people have browsed it


        function get_Pass_Date($ymdhms1,$ymdhms2){
            $datetime1 = date_create("$ymdhms1");
            $datetime2 = date_create("$ymdhms2");
            $interval = date_diff($datetime1, $datetime2);
            $psdate=null;
            if($interval->y>0){
                $psdate= $interval->format('%y 年%m 月%d 天%h 时%i 分%s 秒');
            }else if($interval->m>0){
                $psdate= $interval->format('%m 月%d 天%h 时 %i 分%s 秒');
            }else if($interval->d>0){
                $psdate= $interval->format('%d 天%h 时 %i 分 %s 秒');
            }else if($interval->h>0){
                $psdate= $interval->format('%h 时%i 分%s 秒'); 
            }else if($interval->i>0){
                $psdate= $interval->format('%i 分%s 秒');
            }else{
                $psdate=$interval->format('%s 秒');
            } 
            return $psdate;
        }
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