PHP-mysql中的时间戳差异

PHP-mysql中的时间戳差异,php,mysql,time,difference,Php,Mysql,Time,Difference,我想得到两个php时间戳之间的确切时间差。 &我正在使用这个代码 代码1: &如果打印这个$h和$m-我得到了我想要的东西, 两个时间戳之间的差异 现在我想从我的桌子上拿到d2美元 我在mysql表中存储了一个时间戳作为数据类型TIME 如下 代码2 但是当我打印$h和$m时,我没有正确地得到值。。。 请任何人帮我这么做 代码1工作得很好,但当我尝试执行代码2时,它显示了一些垃圾值,而不是我期望的值 请。以下是这个问题的正确答案 $d1=strtotime(date('H:i:s'));

我想得到两个php时间戳之间的确切时间差。 &我正在使用这个代码

代码1:

&如果打印这个$h和$m-我得到了我想要的东西, 两个时间戳之间的差异

现在我想从我的桌子上拿到d2美元

我在mysql表中存储了一个时间戳作为数据类型TIME

如下

代码2

但是当我打印$h和$m时,我没有正确地得到值。。。 请任何人帮我这么做

代码1工作得很好,但当我尝试执行代码2时,它显示了一些垃圾值,而不是我期望的值


请。以下是这个问题的正确答案

  $d1=strtotime(date('H:i:s'));      //current time consider e.g 15:00:00

  $d2=strtotime($rows['showtime']);  //where $rows['showtime'] is the timestamp stored in mysql table. consider it as 18:00:00

  $all = round(abs($d2 - $d1) / 60);
  $d = floor ($all / 1440);
  $h = floor (($all - $d * 1440) / 60);
  $m = $all - ($d * 1440) - ($h * 60);

使用那边的abs。

显示var_dump$行['showtime']的输出。您好,我将此作为输出-string8 13:00:00Change$all=round$d2-$d1/60;至$all=roundabs$d2-$d1/60;嘿,谢谢你,伙计,谢谢你。。。你解决了。。。。。现在工作正常了……那么写一个答案并把问题标记为已解决,怎么样?
    $d1=strtotime(date('H:i:s'));      //current time consider e.g 15:00:00

$d2=strtotime($rows['showtime']);  //where $rows['showtime'] is the timestamp stored in mysql table. consider it as 18:00:00

$all = round(($d2 - $d1) / 60);
$d = floor ($all / 1440);
$h = floor (($all - $d * 1440) / 60);
$m = $all - ($d * 1440) - ($h * 60);
  $d1=strtotime(date('H:i:s'));      //current time consider e.g 15:00:00

  $d2=strtotime($rows['showtime']);  //where $rows['showtime'] is the timestamp stored in mysql table. consider it as 18:00:00

  $all = round(abs($d2 - $d1) / 60);
  $d = floor ($all / 1440);
  $h = floor (($all - $d * 1440) / 60);
  $m = $all - ($d * 1440) - ($h * 60);