1

PHP 4

$a = 1359994013   (Mon, 04 Feb 2013 16:06:53)
$b = 1359997483   (Mon, 04 Feb 2013 17:04:43)

如何计算这两个时间戳之间的差异并将结果显示为:

w days, x hours, y mins, z seconds.

例如:0 天、0 小时、58 分钟、10 秒

谢谢 :)

4

2 回答 2

6

如果您参与计算并坚持使用 PHP 4:

$a = 1359994013;
$b = 1359997483;

$difference = $b-$a;

$second = 1;
$minute = 60*$second;
$hour   = 60*$minute;
$day    = 24*$hour;

$ans["day"]    = floor($difference/$day);
$ans["hour"]   = floor(($difference%$day)/$hour);
$ans["minute"] = floor((($difference%$day)%$hour)/$minute);
$ans["second"] = floor(((($difference%$day)%$hour)%$minute)/$second);
echo $ans["day"] . " days, " . $ans["hour"] . " hours, "  . $ans["minute"] . " minutes, " . $ans["second"] . " seconds";

这给你0 days, 0 hours, 57 minutes, 50 seconds

于 2013-02-04T17:21:17.900 回答
0

您可以尝试使用日期功能:

http://php.net/manual/it/function.date.php

于 2013-02-04T17:11:39.053 回答