2016-12-02 61 views
0

我想要從2個不同鏈接獲得2個時間戳,並比較差異是否大於10分鐘。如果是這樣,我想打印一條消息。比較2號碼和打印信息是否大於10

時間戳的格式如下:

週五,2016年12月2日18點47分40秒GMT

這是我的代碼:

$1=get_headers("http://example.com", 1); 
$2=get_headers("http://example1.com", 1); 
$a1=$1["Last-Modified"]; 
$a2=$2["Last-Modified"]; 

$mins = ($a1- $a2)/60; 
echo $mins; 

,然後我想接下來是這樣的:

$mins > 10  
echo "its bigger then 10"; 
+1

什麼是你的問題? –

回答

2

您應該使用strtotime函數將字符串格式轉換爲數字格式(結果是從1/1/1970過去的秒數)。一旦你的值作爲數字你可以做你的數學:

$headers_1=get_headers("http://example.com", 1); 
$headers_2=get_headers("http://example1.com", 1); 

$a1 = strtotime($headers_1["Last-Modified"]); 
$a2 = strtotime($headers_2["Last-Modified"]); 

$mins = ($a1-$a2)/60; 
if ($mins > 10) { 
    echo "its bigger then 10"; 
} 
+0

舉例現在這個星期五,2016年12月02日20:16:33 GMT 已轉換爲1480709793:你可以exmplain這個號碼是什麼 – arpak

+0

是什麼?我不明白這個評論是關於 – Dekel

+0

所以echo $ mins;是告訴2倍之間的差距有多少? – arpak