怎么才能得到两个日期的差值? mktime和strtotime得到的都是Unix timestamp,两个Unix timestamp相减就是两个日期相差的秒数,如果需要得到天数、小时数,作个除法即可 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 up---------------------------------------------------------------------------------------------腰缠70元到月入近10万http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=453IT工程师 毕业4年我年薪涨到30万 http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=51126岁青年坐拥千万域名资产 从小玩家变成CEO http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=515程序员的酸甜苦辣:告别Coding http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=341从月薪3500到700万(一)http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=170网络草根月赚3000的十种方法http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=517如果我是女的 我肯定不会嫁给做网站的http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=512 //------------------------------------------------------------------------------- // 時間格式 YYYY-MM-DD HH:mm:ss //------------------------------------------------------------------------------- function timeDiff($aTime,$bTime,$id){ //去掉時間裡面的'-',' ',':'符號 $aTime_u = str_replace("-","",str_replace(" ","",str_replace(":","",$aTime))); $bTime_u = str_replace("-","",str_replace(" ","",str_replace(":","",$bTime))); //分割第一個時間 $ayear = substr($aTime_u,0,4); $amonth = substr($aTime_u,4,2); $aday = substr($aTime_u,6,2); $ahour = substr($aTime_u,8,2); $aminute = substr($aTime_u,10,2); $asecond = substr($aTime_u,12,2); //分割第二個時間 $byear = substr($bTime_u,0,4); $bmonth = substr($bTime_u,4,2); $bday = substr($bTime_u,6,2); $bhour = substr($bTime_u,8,2); $bminute = substr($bTime_u,10,2); $bsecond = substr($bTime_u,12,2); //生成時間戳 $a = mktime($ahour,$aminute,$asecond,$amonth,$aday,$ayear); $b = mktime($bhour,$bminute,$bsecond,$bmonth,$bday,$byear); $timeDiff['second'] = $a-$b; //採用了四捨五入,可以修改 $timeDiff['mintue'] = round($timeDiff['second']/60); $timeDiff['hour'] = round($timeDiff['mintue']/60); $timeDiff['day'] = round($timeDiff['hour']/24); $timeDiff['week'] = round($timeDiff['day']/7); $timeDiff['month'] = round($timeDiff['day']/30); //按30天來算 $timeDiff['year'] = round($timeDiff['day']/365); //按365天來算 if ($id == 1){ if ($timeDiff['mintue']>0){ $date_mgs = substr($aTime,0,10); }else{ $date_mgs = DATE_GQ; } }elseif ($id == 0){ $date_mgs = $timeDiff['mintue']; } return $date_mgs; }} 我已经计算出来是多少秒了,但是我使用date("h:i:s")来表示的时候却表示不出来? 你要表示什么,不要告诉我要用date("h:i:s")表示差值~=_=! 如果你是想具体计算出两个日期之间间隔的天数的话,下面的代码就可以实现:$birth_year=date("Y",strtotime($myrow["birthdate"])); $birthdate=date("m-d",strtotime($myrow["birthdate"])); $d1=strtotime($birth_year."-".$birthdate); //recorded$d2=strtotime(date("Y-m-d")); //now$diff=$d1-$d2; //seconds$diff=$diff/3600/24; //daythe $diff is what you want php中的位运算具体应用哪位朋友有实例,请指教,多谢! 关于php的反向引用 哪位高人给介绍一下fsockopen的应用? 如何判断主机是否在线 虚拟主机如何配置日志文件?并实现不同权限的访问? 我的首页是静态的,如何让他自己隔3个小时更新一次 对于php程式, 可不可以单步执行并调试程式的!(就类似delphi的F8功能!) php中有没有象asp中的application功能,我要怎么才能实现该功能?? phplib得template类在处理模板得图象上有问题哦。 PHP路径编码问题,求大神指点 这个用php咋写啊,怎么写都错 求BT发布程序一份,非小偷程序。
腰缠70元到月入近10万
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=453IT工程师 毕业4年我年薪涨到30万
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=51126岁青年坐拥千万域名资产 从小玩家变成CEO
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=515程序员的酸甜苦辣:告别Coding
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=341从月薪3500到700万(一)
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=170网络草根月赚3000的十种方法
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=517如果我是女的 我肯定不会嫁给做网站的
http://www.hunbei.com.cn/Article/ArticleShow.asp?ArticleID=512
// 時間格式 YYYY-MM-DD HH:mm:ss
//-------------------------------------------------------------------------------
function timeDiff($aTime,$bTime,$id){
//去掉時間裡面的'-',' ',':'符號
$aTime_u = str_replace("-","",str_replace(" ","",str_replace(":","",$aTime)));
$bTime_u = str_replace("-","",str_replace(" ","",str_replace(":","",$bTime)));
//分割第一個時間
$ayear = substr($aTime_u,0,4);
$amonth = substr($aTime_u,4,2);
$aday = substr($aTime_u,6,2);
$ahour = substr($aTime_u,8,2);
$aminute = substr($aTime_u,10,2);
$asecond = substr($aTime_u,12,2);
//分割第二個時間
$byear = substr($bTime_u,0,4);
$bmonth = substr($bTime_u,4,2);
$bday = substr($bTime_u,6,2);
$bhour = substr($bTime_u,8,2);
$bminute = substr($bTime_u,10,2);
$bsecond = substr($bTime_u,12,2);
//生成時間戳
$a = mktime($ahour,$aminute,$asecond,$amonth,$aday,$ayear);
$b = mktime($bhour,$bminute,$bsecond,$bmonth,$bday,$byear);
$timeDiff['second'] = $a-$b;
//採用了四捨五入,可以修改
$timeDiff['mintue'] = round($timeDiff['second']/60);
$timeDiff['hour'] = round($timeDiff['mintue']/60);
$timeDiff['day'] = round($timeDiff['hour']/24);
$timeDiff['week'] = round($timeDiff['day']/7);
$timeDiff['month'] = round($timeDiff['day']/30); //按30天來算
$timeDiff['year'] = round($timeDiff['day']/365); //按365天來算
if ($id == 1){
if ($timeDiff['mintue']>0){
$date_mgs = substr($aTime,0,10);
}else{
$date_mgs = DATE_GQ;
}
}elseif ($id == 0){
$date_mgs = $timeDiff['mintue'];
}
return $date_mgs;
}
}
$birth_year=date("Y",strtotime($myrow["birthdate"]));
$birthdate=date("m-d",strtotime($myrow["birthdate"]));
$d1=strtotime($birth_year."-".$birthdate); //recorded
$d2=strtotime(date("Y-m-d")); //now
$diff=$d1-$d2; //seconds
$diff=$diff/3600/24; //daythe $diff is what you want