时间差在小时分秒秒

时间:2014-08-19 18:09:45

标签: php datetime time

使用这样的公式

<?php
//Coming From Mobile Phone
$Currenttime   = 12:40:00;
//Server time Is Current Time of various timezone like(America/Chicago,America/Denver..)
$ServerTime   = 12:55:00;
//Scheduletime is coming from database
$ScheduleTime = 14:45:00;

$ExactTime    = ($Currenttime - $ServerTime) + $ScheduleTime

?>

我需要Exact Time就像这个15:00:00

1 个答案:

答案 0 :(得分:2)

您应该使用DateTime类:

$Currenttime  = DateTime::createFromFormat('H:i:s', "12:40:00");
$ServerTime   = DateTime::createFromFormat('H:i:s', "12:55:00");
$ScheduleTime = DateTime::createFromFormat('H:i:s', "14:45:00");

$ExactTime    = $ScheduleTime->add($Currenttime->diff($ServerTime));