2009-12-20 61 views
0

在一個項目上,我有一個內部時間計算。時間戳到內部日計數

自啓動的日子簡單地列舉:

2009/10/19:每天推出 2009/10/20:每日1 2009/10/21:2天 等

現在我想要有一個函數給我當前內部計算時間的日子。例如。在2010年

但重要的是第一天 「一二天」 有這樣的精度:

2009/10/20 00:00:01 =>第1天 2009/10/20 23:59 :59 =>第1天 2009/10/21 00:00:01 =>第2天

我構建了以下功能,但它沒有那個準確性。爲什麼不?你能改善它嗎?

function date2daycount($timestamp) { 
$launchDay = 1255903200-3600*24; // launch (2009/10/19 00:00:00) 
$difference = floor(($timestamp-$launchDay)/86400); // days after launch 
return $difference; 
} 

在此先感謝!

回答

0
function date2daycount($timestamp) { 
$launchDay = strtotime('19 October 2009'); // launch (2009/10/19 00:00:00) 
$difference = floor(($timestamp-$launchDay)/86400); // days after launch 
return $difference+1; 
} 
+0

謝謝你的回答,但strtotime('19十月2009')給我的服務器返回1255903200。這就是我在這個問題上寫的。 – caw 2009-12-21 15:44:54

+0

但是'-3600 * 24'是什麼? – 2009-12-21 16:21:51

+0

當您回來升級系統並修改此代碼時,使用strtotime更加詳細和可讀 – 2009-12-21 16:22:49