標籤:php 時間戳記
有時候,要比較兩個時間之間相差的天數
可以採用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時間戳記
---------------------------------分割線-----------------------------------------
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/59/58/wKioL1TQj96zSH4FAACgA6df4xY007.jpg" title="QQ20150203092742.png" alt="wKioL1TQj96zSH4FAACgA6df4xY007.jpg" />
END!
本文出自 “百折不回” 部落格,請務必保留此出處http://changbo.blog.51cto.com/1316452/1611193
PHP時間戳記比較