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?
$now->diffInSeconds($emitted);
is exactly what I needed. One note is that $emitted doesn't appear to need to be a parsed carbon object; an ISO8601 formatted string worked fine for me. – Chantal