使用strtotime的时差

Ron*_*den 4 php

这应该不难,但我仍然不明白发生了什么.

<?php
    echo date( 'H:i', strtotime( '09:00' ) - strtotime( '08:00' ) ); 
    // returns 02:00 instead of 01:00

    echo date( 'H:i', strtotime( '18:45' ) - strtotime( '17:15' ) ); 
    // returns 02:30 instead of 01:30

    echo date( 'H:i', strtotime( '17:00' ) - strtotime( '09:00' ) );
    // returns 09:00 instead of 08:00
Run Code Online (Sandbox Code Playgroud)

什么是额外的小时?

也许我需要添加日期?

<?php
    echo date( 'H:i', strtotime( '22-09-2016 17:00:00' ) - strtotime( '22-09-2016 09:00:00' ) );
    // still 09:00 instead of 08:00
Run Code Online (Sandbox Code Playgroud)

一些额外的信息

我在Xampp中使用Laravel测试版.

在Laravel /config/app.php中 'timezone' => 'Europe/Amsterdam',

在Xampp date_default_timezone_set('Europe/Amsterdam');

仍然没有区别.

此计算在刀片模板中完成,我无法访问DateTime类.

我找到了一种使用DateTime类的方法.另一种解决方案是将时区更改为UTC,但后来所有其他时间戳都是错误的.

Rak*_*tra 5

使用DateTime对象找到差异

$time1 = new DateTime('18:45');
$time2 = new DateTime('17:15');
$interval = $time1->diff($time2);
echo $interval->format('%H:%I');
Run Code Online (Sandbox Code Playgroud)