Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php strottime(秒和分钟)_Php_Date_Strtotime_Date Math - Fatal编程技术网

php strottime(秒和分钟)

php strottime(秒和分钟),php,date,strtotime,date-math,Php,Date,Strtotime,Date Math,我使用这个方法来查找两个时间戳之间的差异,并获得这两个时间戳之间的秒数,然后像计数器一样使用jquery刷新信息 $diff = strtotime(date('Y-m-d H:i:s')) - strtotime('2014-06-25 14:50:03'); $time = intval(date('s', $diff)); echo $time; 当差值超过60秒时,$时间返回到0,就像重置一样 我想显示1分钟XX秒,例如date()的s标志将永远不会返回大于59的值,因为它只表示给定时

我使用这个方法来查找两个时间戳之间的差异,并获得这两个时间戳之间的秒数,然后像计数器一样使用jquery刷新信息

$diff = strtotime(date('Y-m-d H:i:s')) - strtotime('2014-06-25 14:50:03');
$time = intval(date('s', $diff));
echo $time;
当差值超过60秒时,$时间返回到0,就像重置一样


我想显示1分钟XX秒,例如
date()
s
标志将永远不会返回大于59的值,因为它只表示给定时间的当前秒数,在滚动到新分钟之前,该秒数永远不会超过59

如果需要总秒数,您可以实际删除第二行代码,因为两个Unix时间戳之间的差异始终以秒为单位:

$time = strtotime(date('Y-m-d H:i:s')) - strtotime('2014-06-25 14:50:03');
echo $time;
如果要将其显示为分钟和秒,可以使用
DateTime()
,它提供了更好的工具:

$now = new DateTime();
$then = new DateTime('2014-06-25 14:50:03');
$diff = $now->diff($then);
echo $diff->format('%i minutes %s seconds');
格式化日期

$diff = strtotime(date('Y-m-d H:i:s')) - strtotime('2014-06-25 14:50:03');
$time = date('i:s', $diff);
echo $time;

像1一样消磨时间&现在是2

function diffrencePassTimeAction($DataTime){
    $im = $DataTime - strtotime("now");
  return $im;
}
未来时间如2&现在为1

function diffrenceFuturTimeAction($DataTime){
    $im = strtotime("now") - $DataTime;
  return $im;
}
此函数用于删除(-less)


对我来说很合适。
function diffrencePassTimeAction($DataTime){
    if ($DataTime > 0)
        return $DataTime - strtotime("now");
    else
        return strtotime("now"); // OR return 0;
}