如何避免在php中减去拖时间时添加时区

如何避免在php中减去拖时间时添加时区,php,datetime,time,timezone,Php,Datetime,Time,Timezone,我的php时区是亚洲/达卡(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) 如何避免从此输出中添加时区时间?尝试使用php日期时间 $a = '11:00:00'; $b = '09:00:00'; $start_date = new

我的php时区是亚洲/达卡(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)

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

尝试使用php日期时间

$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}";

您好,努尔,在运行此操作之前,您是否尝试过将默认时区设置为“亚洲/达卡”。@Rohit Batra默认时区在我的应用程序中设置为“亚洲/达卡”。如果您使用
echo$since_start->格式(“%H:%I:%S”)格式化输出,效果会更好