如何在PHP中将Date转换回来?

时间:2012-11-28 17:27:48

标签: php date time format

任何请帮我转换回原始日期格式,试图使用strtotime($startDate)并给出一个非常错误的答案!

$startDate = '2012-11-21T20:16:14+02:00';
$endDate = '2012-11-27T23:19:14+02:00';

$date = 2012-11-26;
$time = 20:16:14;
$duration = $endDate - $startDate; // 01:30:00

1 个答案:

答案 0 :(得分:1)

这应该有效:

$startDate = '2012-11-21T20:16:14+02:00';
$endDate = '2012-11-27T23:19:14+02:00';

$duration = strtotime($endDate) - strtotime($startDate);
// 60 seconds * 60 minutes * 24 hours
$days = round($duration / (60 * 60 * 24));
echo 'days difference: '.$days;