可以计算任意时间差的函数
时间:2007-02-17 来源:PHP爱好者
<?
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
function diff($day1,$day2)
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
{
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
$a=explode("-",$day1);
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
$b=explode("-",$day2);
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
if(checkdate($a[1],$a[2],$a[0]) && checkdate($b[1],$b[2],$b[0]))
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
{
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
$c=mktime(0,0,0,$a[1],$a[2],$a[0]);
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
$d=mktime(0,0,0,$b[1],$b[2],$b[0]);
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
$f=($d-$c)/3600/24;
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
echo "$day1 和 $day2 之间相差 $f 天!";
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
}
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
else
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
{
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
print "对不起,你的日期格式不对!";
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
}
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
}
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
//用法
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
diff("2001-1-1","2001-3-1");
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
?>
php爱好者站 http://www.phpfans.net Linux|Apache|IIS.
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
function diff($day1,$day2)
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
{
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
$a=explode("-",$day1);
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
$b=explode("-",$day2);
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
if(checkdate($a[1],$a[2],$a[0]) && checkdate($b[1],$b[2],$b[0]))
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
{
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
$c=mktime(0,0,0,$a[1],$a[2],$a[0]);
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
$d=mktime(0,0,0,$b[1],$b[2],$b[0]);
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
$f=($d-$c)/3600/24;
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
echo "$day1 和 $day2 之间相差 $f 天!";
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
}
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
else
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
{
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
print "对不起,你的日期格式不对!";
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
}
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
}
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
//用法
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
diff("2001-1-1","2001-3-1");
ww w.china it power.co9NAskd5I1Ip6xoiUvnNuduPvU
?>
php爱好者站 http://www.phpfans.net Linux|Apache|IIS.
相关阅读 更多 +