|
有时候,要比较两个时间之间相差的天数
可以采用strtortime()函数,该函数预期接受一个包含英文日期格式的
字符串,并尝试将其解析为UNIX时间戳
int strtotime(string time [,int now]);
strtotime()函数有两个参数。如果参数time的格式是绝对时间,
则now参数不起作用,如果参数time的格式是相对时间,其对应的
时间由参数now来提供。
<?php
$a=strtotime("now"); //获取当前时间的时间戳-秒数
$b=strtotime("05 May 2010"); //获取指定时间的时间戳-秒数
echo $a."\n"; //输出获取的时间戳
echo "输出日期".date("Y-m-d H:i:s",$a)."<br/><br/>"; //格式化输出时间戳
echo $b."\n"; //输出指定时间的时间戳
echo "输出日期".date("Y-m-d H:i:s",$b)."<br><br/>"; //格式化输出指定时间时间戳
$c=ceil(($a-$b)/(3600*24)); //返回一个整数
echo "距2010年5月5日已过去".$c."天";
?>
注意,在unxi系统中,日期与时间表示自1970年1月1日零点起到,到当前时刻的秒数,这种
时间成为UNIX时间戳
---------------------------------分割线--------------
|
|
|