格式为ISO 8601的日期操作?

问题描述:

我需要与日期的PHP操作与格式ISO 8601是这样的:格式为ISO 8601的日期操作?

$starDate = 2012-03-20T00:00:00+01:00; //20 March 2012 
$endDate = 2012-04-01T00:00:00+02:00; // 1 April 2012 

$diff = $starDate - $endDate; //Result should be: 13 

使用此代码$ DIFF得到CERO的值。

+0

复制? http://stackoverflow.com/questions/5988450/difference-between-2-dates-in-seconds and http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-两个日期使用PHP – ChapMic 2012-03-13 19:50:54

试试这个:

function date_diff($date1, $date2) 
{ 
$s = strtotime($date2)-strtotime($date1); 
$d = intval($s/86400)+1; 
return "$d"; 
} 

来源:http://forum.hardware.fr/hfr/Programmation/PHP/php-calculer-nombre-sujet_30415_1.htm

+0

谢谢它为我工作。 – JPashs 2012-03-13 20:26:56