在php中减去两次时如何避免添加时区

时间:2014-11-20 05:40:52

标签: php datetime time timezone

我的php时区是Asia/Dhaka(UTC + 6)

让我有两次时间

$a = 11:00:00;
$b = 09:00:00;
$sub = $a-$b; //it should return 02:00:00. But it adding the timezone and returns 08:00:00 (02:00:00 + 06:00:00)

如何避免从此输出中添加时区时间?

1 个答案:

答案 0 :(得分:0)

尝试使用php DateTime

$a = '11:00:00';
$b = '09:00:00';

$start_date = new DateTime($a);
$since_start = $start_date->diff(new DateTime($b));
echo "{$since_start->h}:{$since_start->i}:{$since_start->s}";