• 比较两个日期的时间差精确到秒


    function timediff($begin_time,$end_time)
    {
        if($begin_time < $end_time){
            $starttime = $begin_time;
            $endtime = $end_time;
        }else{
            $starttime = $end_time;
            $endtime = $begin_time;
        }
    
        //计算天数
        $timediff = $endtime-$starttime;
        $days = intval($timediff/86400);
        //计算小时数
        $remain = $timediff%86400;
        $hours = intval($remain/3600);
        //计算分钟数
        $remain = $remain%3600;
        $mins = intval($remain/60);
        //计算秒数
        $secs = $remain%60;
        $res = array("day" => $days,"hour" => $hours,"min" => $mins,"sec" => $secs);
        return $res;
    }
    $time = '2015-03-20,16:20:30';
    $year=substr($time,0,4);//取得年份
    $month=substr($time,5,2);//取得月份
    $day=substr($time,8,2);//取得几号
    $h = substr($time,11,2);//取得小时
    $i = substr($time,14,2);//取得小时
    $s = substr($time,17,2);//取得小时
    
    $time3 = '2015-05-25,11:10:10';
    $year1=substr($time3,0,4);//取得年份
    $month1=substr($time3,5,2);//取得月份
    $day1=substr($time3,8,2);//取得几号
    $h1 = substr($time3,11,2);//取得小时
    $i1 = substr($time3,14,2);//取得小时
    $s1 = substr($time3,17,2);//取得小时
    $shijian = timediff(strtotime('2015-03-20, 16:20:30'),strtotime('2015-05-25, 11:10:10'));
    echo '从'.$year.'年'.$month.'月'.$day.'日'.$h.'时'.$i.'分'.$s.'秒到'.$year1.'年'.$month1.'月'.$day1.'日'.$h1.'时'.$i1.'分'.$s1.'秒经过了',$shijian['day'],'天'.$shijian['hour'].'时'.$shijian['min'].'分'.$shijian['sec'].'秒';
    

      

  • 相关阅读:
    数据库30条规范
    数据库索引原理
    HashMap的实现原理
    Google 和 Baidu 常用的搜索技巧
    Arrays工具类十大常用方法
    fastjson将json格式null转化空串
    SolrCloud的介绍
    网页背景图片自适应浏览器大小
    addlinkedserver
    常用
  • 原文地址:https://www.cnblogs.com/zheart/p/6518362.html
Copyright © 2020-2023  润新知