PHP-显示时间在两个小时之间

时间:2019-02-19 16:37:07

标签: php date datetime time

我有四个字段,使用这些字段显示它们之间的经过时间。 这是我的php代码:

// Days elapsed from the moment of the creation to the date of the visit
$date1   = $ticket->date_at;
$date2   = $ticket->visit_date;
$diff    = abs(strtotime($date2) - strtotime($date1));

// Specific time elapsed between the dates, (days, months and years)
$years   = floor($diff / (365*60*60*24));
$months  = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days    = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

// Hours elapsed
$horallamada   = strtotime($ticket->time_at);
$horavis = strtotime($ticket->visit_hour_in);
$horasal   = strtotime($ticket->visit_hour_out);
$hdiff   = $horallamada   - $horasal;
$hvisdiff = $horallamada   - $horavis;
$hsolution = $horavis - $horasal;

// printing of the time elapsed to answer the ticket
printf("<p>This ticket was answered in ");  
echo gmdate("H:i", abs($hvisdiff)); printf(" hours.</p>");

// printing of the time elapsed to solve the ticket
printf("<p>This ticket was solved in ");
echo gmdate("H:i", abs($hsolution)); printf(" hours.</p>");

// total time elapsed calculation
printf("This ticket was closed in %d years, %d months, %d days and \n", $years, $months, $days);
echo gmdate("H:i", abs($hdiff)); printf(" hours after the date of creation.");

$hvisdiff$hsolution$hdiff将返回差异为“ 02:36”,即02 小时 和36分钟 分钟

如何让它像这样显示?

赞:

  

此票在02小时36分钟内得到答复

     

这张票在01小时6分钟内解决了

     

此票证在创建日期后的x年,x个月,x天,03小时零46分钟关闭。

我尝试了以下this教程,但是,它不起作用。我该如何实现?

0 个答案:

没有答案