Monday, April 10, 2017

Difference between two times in seconds on carbon based on timezone

I want to find out the difference between 2 times for the different timezone. My server is based on Sydney and I want to find the difference between given time and current time(based on Perth) in seconds

    echo $tz = Carbon::now('Australia/Perth');
    echo "<br>";
    $local='2017-04-11 12:39:50';
    echo $emitted = Carbon::parse($local);
    echo "<br>";
    echo "diff from carbon->";
    echo $diff = $tz->diffInSeconds($emitted); 
    echo "<br> diff from Normal->";
    echo  $diff1 = strtotime($tz) - strtotime($emitted);

When I used diffInSeconds it gave 2 hours difference and looks like localisation is not taken consideration but strtotime($tz) - strtotime($emitted) gives perfect result. Any thing I missed?



via sumit

Advertisement