0

I am trying to get diffrence in both the timestamp i dont know what i am missing.

parts of my codes here.

$newtime = 1368250840;
$oldtime = 1171502725;
$diffrence = $newtime - $oldtime;
echo $diffrence;                   // 196748115 till here its fine
$date = $date->setTimestamp("$diffrence"); // problem here
echo $date->format('H:i:s') . "\n";       

I try changing it to

$date = $date->setTimestamp('$diffrence');

and this

$date = $date->setTimestamp(' . $diffrence . ');

Any solution plz :) Thanks

4

3 回答 3

2

尝试,

$date = new DateTime("@$diffrence");
echo $date->format('H:i:s') . "\n";

或者

$date = new DateTime();
$date->setTimestamp( $diffrence);
echo $date->format('H:i:s'); 
于 2013-05-11T05:58:10.390 回答
0

使用date_diff()方法!

<?php
  $datetime1 = new DateTime('2009-10-11');
  $datetime2 = new DateTime('2009-10-13');
  $interval = $datetime1->diff($datetime2);
  echo $interval->format('%R%a days');
?>
于 2013-05-11T05:59:41.847 回答
0

date如果您不需要该对象,可以只使用 PHP 的函数。

echo date("H:i:s", $diffrence);
于 2013-05-11T06:02:33.487 回答