Carbon Time Difference of Local Time and Server Time
<p>I am using Laravel 4 and trying to calculate the difference of the Time on Server and the Time Save in Database in hours. Here is the code:</p>

<p>Time on Server=timeNowOnServer   // 2016-02-03 19:05:43
Time saved in Database = setTime // 18:00:00</p>

<pre><code>        $timeNowOnServer = null;
        $setTime = null;

        $timeZone = $company-&gt;time_zone;
        $company-&gt;save();

        // My Time
        $hour = substr($company-&gt;emp_auto_logout_time, 0, 2);
        $setTime = Carbon::createFromTime($hour);

        // Server Time Same as Mine
        $timeNowOnServer = Carbon::now();
        $timeNowOnServerSameAsMine = $timeNowOnServer-&gt;setTimezone($timeZone);

        // Time Differnce Between SetTime and TimeOnServerSameAsMine
        $timeDiff = $setTime-&gt;diffInHours($timeNowOnServerSameAsMine, $abs = false);
</code></pre>

<p>If <code>Server Time</code> is 14:00:00 for example and <code>Set Time</code> is 19:00:00. My time zone is <code>GMT +5 Pakistan</code>.</p>

<p>What I'm doing is, adding setting <code>Server Time</code> according to user time by giving <code>time zone</code> in the 3rd last line of the above given code.</p>

<p>When I use <code>diffInHour</code> it instead of giving me 0 it gives me -5 or 5. It means it's useing <code>UTC (Server Time)</code> and that's why give wrong difference in hours.</p>

<p>Can someone please let me know where I'm wrong?</p>