Reputation: 27038
i've got 2 time stamps: $start_time = 1312346227;
and $end_time = 1312346466;
and i am trying to substract them to see the time inbetween $end_time = $end_time - $start_time;
and i get 239
.
What is the proper way of converting this to a human readable date?
if i try echo date("h:i:s A",$end_time);
i get 04:03:59
and it should be 00:03:59
any ideas? Thanks
Upvotes: 1
Views: 86
Reputation: 449395
If you have PHP 5.3, use the DateInterval
class.
Example stolen from the manual page on DateInterval::format()
:
<?php
$january = new DateTime('2010-01-01');
$february = new DateTime('2010-02-01');
$interval = $february->diff($january);
// %a will output the total number of days.
echo $interval->format('%a total days')."\n";
// While %d will only output the number of days not already covered by the
// month.
echo $interval->format('%m month, %d days');
?>
Upvotes: 4
Reputation: 62369
You get addiionl four hours, because of your timezone. Remember that unix timestamp is the number of seconds since 1970-01-01 00:00:00 UTC. If you (or your server) are in UTC+4 TZ, then date()
will implicitly do a timezone conversion to your local time.
Solution? Use gmdate()
instead
Upvotes: 3
Reputation: 705
You need to set your timezone correctly. http://www.php.net/manual/en/function.date-default-timezone-set.php
Upvotes: 1