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;
}
//======== 实例使用 ========
$timediff = timediff( strtotime( "2011-10-28" ), strtotime( "2011-10-29" ) );
print_r( $timediff );

还有

<?php
$one = strtotime('2011-12-08 07:02:40');//开始时间 时间戳
$tow = strtotime('2011-12-25 00:00:00');//结束时间 时间戳
$cle = $tow - $one; //得出时间戳差值 /* 这个只是提示
echo floor($cle/60); //得出一共多少分钟
echo floor($cle/3600); //得出一共多少小时
echo floor($cle/3600/24); //得出一共多少天
*/
/*Rming()函数,即舍去法取整*/
$d = floor($cle/3600/24);
$h = floor(($cle%(3600*24))/3600); //%取余
$m = floor(($cle%(3600*24))%3600/60);
$s = floor(($cle%(3600*24))%60); echo "两个时间相差 $d 天 $h 小时 $m 分 $s 秒"

php计算时间差/两个时间日期相隔的天数,时,分,秒.的更多相关文章

  1. php自定义函数: 计算两个时间日期相隔的天数,时,分,秒

    function timediff( $begin_time, $end_time ) { if ( $begin_time < $end_time ) { $starttime = $begi ...

  2. javascript中计算两个时间日期间隔的天数

    <script>              /*                  计算两个日期的时间间隔天数              */              //时间字符串的格 ...

  3. oracle截取时间的年/月/日/时/分/秒

    修改日期格式为年月日时分秒: alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';select to_char(sysdate,'yyy ...

  4. C#WinForm中显示实时时间:年/月/日 时/分/秒 星期X

    //加载窗体时 string weekstr = ""; private void Form22_Load(object sender, EventArgs e) { this.t ...

  5. [Windows]获取当前时间(年/月/日/时/分/秒)

    struct tm* GetCurTime(time_t inTime) { struct tm* curTime = localtime(&inTime); curTime->tm_y ...

  6. Java计算两个字符串日期之间的天数差

    Java计算两个字符串日期之间的天数差 调用方法: public static void main(String[] args) throws ParseException { String a = ...

  7. JAVA 时间差距,两个时间相差多少天,时,分,秒

    JAVA 时间差距,两个时间相差多少天,时,分,秒 package io; import java.text.DateFormat; import java.text.ParseException; ...

  8. python的N个小功能(文本字段对应数值,经纬度计算距离,两个时间点计算时间间隔)

    案例1 >>> import pandas as pd >>> df=pd.DataFrame({'A':[1,2,3],'B':[1,2,3],'C':[1,2, ...

  9. DB2--sql计算时间差和格式化时间

    格式化时间 db2 格式化时间使用的 TO_CHAR(TIMESTAMP('2017-10-24 21:18:12'),'YYYY-MM-DD'): 测试sql:SELECT TO_CHAR(TIME ...

随机推荐

  1. udev:renamed network interface eth0 to eth1

    删除/etc/udev/rules.d/70-persistent-net.rules这个文件,重启

  2. Live555 Streaming from a live source

    https://www.mail-archive.com/live-devel@lists.live555.com/msg05506.html-----ask--------------------- ...

  3. Django中的cookie与session

    cookie与session的实现原理 HTTP被设计为”无状态”,每次请求都处于相同的空间中. 在一次请求和下一次请求之间没有任何状态保持,我们无法根据请求的任何方面(IP地址,用户代理等)来识别来 ...

  4. 简单之美 | ZooKeeper应用案例

    简单之美 | ZooKeeper应用案例 ZooKeeper应用案例

  5. c盘没有新建修改权限的,执行下面命令

    cmd中执行: icacls c:\ /setintegritylevel M

  6. ng-if与ng-show、ng-hide指令的区别和注意事项

    http://blog.csdn.net/aitangyong/article/details/44701769

  7. javascript之文档碎片,文档碎片在理论上可以提高DOM操作的执行效率

    刚来到这里,趁着还没有忘记,来记录一下,昨晚学习的一个知识点——JavaScript中的文档碎片. 一.对文档碎片的基本认识 文档碎片可以提高DOM操作性能(理论上,注意!!理论上的) 文档碎片原理 ...

  8. [struts2学习笔记] 第一节 关于struts2的简单认知

    本文地址:http://blog.csdn.net/sushengmiyan/article/details/40298287 官方文档:http://struts.apache.org/releas ...

  9. Linux kernel驱动相关抽象概念及其实现 之“linux设备模型kobject,kset,ktype”

    kobject,kset,ktype三个很重要的概念贯穿Linux内核驱动架构,特转载一篇博文: (转载自http://blog.csdn.net/gdt_a20/article/details/64 ...

  10. c++ 文件写样例

    #include <iostream> #include <sstream> #include <fstream>> using namespace std; ...