zoukankan      html  css  js  c++  java
  • php date 时间差

    date 时间

    时间第二个参数0 1970-01-01
    时间第二个参数是负数 小于1970-01-01

    日期比较

    strtotime() 转为 时间戳
    date("Y-m-d",strtotime("-1 day"));
    date("Y-m-d",strtotime("-1 month"));
    date("Y-m-d",strtotime("-1 year"));
    

    时间差

    $zero1 = strtotime(date("Y-m-d h:i:s"));
    $zero2=strtotime ("2022-1-21 00:00:00");  //过年时间,不能写2014-1-21 24:00:00  这样不对 
    $guonian=ceil(($zero2-$zero1)/86400); //60s*60min*24h   
    echo "离过年还有<strong>$guonian</strong>天!"; 
    
    //PHP计算两个时间差的方法 
    $startdate="2021-12-12 11:40:00";
    $enddate="2021-12-12 18:32:09";
    $date=floor((strtotime($enddate)-strtotime($startdate))/86400);
    $hour=floor((strtotime($enddate)-strtotime($startdate))%86400/3600);
    
    $minute=floor((strtotime($enddate)-strtotime($startdate))%86400%3600/60);
    
    $second=floor((strtotime($enddate)-strtotime($startdate))%86400%60);
    echo $date."天<br>";
    echo $hour."小时<br>";
    echo $minute."分钟<br>";
    echo $second."秒<br>";
    
  • 相关阅读:
    手机发送验证码—.net代码
    AJAX之XMLHttpRequest
    JQuery总结+实例
    ASP.NET总结——更改后
    css总结——position
    JavaScript的程序构成
    初识javascript
    asp总结
    北大青鸟代码---asp.net初学者宝典
    iOS常用技术-Label自适应
  • 原文地址:https://www.cnblogs.com/corvus/p/14455305.html
Copyright © 2011-2022 走看看