php计算时间差/两个时间日期相隔的天数,时,分,秒.
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计算时间差/两个时间日期相隔的天数,时,分,秒.的更多相关文章
- php自定义函数: 计算两个时间日期相隔的天数,时,分,秒
function timediff( $begin_time, $end_time ) { if ( $begin_time < $end_time ) { $starttime = $begi ...
- javascript中计算两个时间日期间隔的天数
<script> /* 计算两个日期的时间间隔天数 */ //时间字符串的格 ...
- oracle截取时间的年/月/日/时/分/秒
修改日期格式为年月日时分秒: alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';select to_char(sysdate,'yyy ...
- C#WinForm中显示实时时间:年/月/日 时/分/秒 星期X
//加载窗体时 string weekstr = ""; private void Form22_Load(object sender, EventArgs e) { this.t ...
- [Windows]获取当前时间(年/月/日/时/分/秒)
struct tm* GetCurTime(time_t inTime) { struct tm* curTime = localtime(&inTime); curTime->tm_y ...
- Java计算两个字符串日期之间的天数差
Java计算两个字符串日期之间的天数差 调用方法: public static void main(String[] args) throws ParseException { String a = ...
- JAVA 时间差距,两个时间相差多少天,时,分,秒
JAVA 时间差距,两个时间相差多少天,时,分,秒 package io; import java.text.DateFormat; import java.text.ParseException; ...
- python的N个小功能(文本字段对应数值,经纬度计算距离,两个时间点计算时间间隔)
案例1 >>> import pandas as pd >>> df=pd.DataFrame({'A':[1,2,3],'B':[1,2,3],'C':[1,2, ...
- DB2--sql计算时间差和格式化时间
格式化时间 db2 格式化时间使用的 TO_CHAR(TIMESTAMP('2017-10-24 21:18:12'),'YYYY-MM-DD'): 测试sql:SELECT TO_CHAR(TIME ...
随机推荐
- ACM1019_最大公倍数
/*问题说明 一组正整数的最小公倍数(LCM)是最小的正整数约数集合中的所有号码. 例如,5,7和15的最小公倍数是105. 输入 输入将包括多个问题的实例.输入的第一行中,将包含一个整数, 表示问题 ...
- PHP中Content-type的MIME类型大全说明
<?php $mimetypes = array( 'ez' => 'application/andrew-inset', 'hqx' => 'application ...
- Spring 的注册与注入
之前和同学老是爱混淆注册与注入.今天再看一遍感觉多了一些理解. 注册就是声明bean.就是让spring能够找到这个bean服务. 注入就是把bean(A)加入到另一个bean(B)的属性中.让另外一 ...
- SQL第二课-创建数据表
查看有多少数据库 SHOW DATABASES; 进入数据库:USE <数据库名> 举例:USE test;//进入test数据库 查看当前进入的是哪个数据库 SELECT DATABAS ...
- [PWA] Keynote: Progressive Web Apps across all frameworks
PWA: Add to home screen Angular Universal Server side rendering: for achieving better proference on ...
- 跟踪MYSQL 的查询优化过程方法
http://dev.mysql.com/doc/internals/en/tracing-example.html http://blog.chinaunix.net/uid-20785090-id ...
- phpnow安装教程
点评:搭建 PHP 其实不很难,只是有点繁琐.要是自己搭建一次 PHP + MySQL 环境很是费时.更糟的是,很多新手在配置 PHP 时常常出现这样那样的问题.诸如 mysql 扩展.zend 安装 ...
- css 权威指南笔记(三)结合css和XHTML
link rel stylesheet alternate stylesheet(候选样式表) title type media all screen print ..... 内联样式
- Objective-C:swift、objective-c、C++、C混合编程
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css); @import url(/ ...
- nest 'for' loop.
/* nest for loop demo. Note that,'upside' triangle controls 'inner condition'. */ import kju.print.P ...