Time difference in PHP using timezone function?

前端 未结 1 752
长情又很酷
长情又很酷 2021-01-27 09:10

I am trying to find a way to display a difference in time between two locations using timezone function in PHP: http://php.net/manual/en/timezones.php

lets say I have ch

1条回答
  •  伪装坚强ぢ
    2021-01-27 09:30

    function get_timezone_offset( $origin_tz, $remote_tz ) {
        $timezone1 = new DateTimeZone( $origin_tz );
        $timezone2 = new DateTimeZone( $remote_tz );
    
        $datetime1 = new DateTime("now", $timezone1);
        $datetime2 = new DateTime("now", $timezone2);
    
        $offset = $timezone1->getOffset($datetime1) - $timezone2->getOffset($datetime2);
        return $offset;
    }
    
    $offset = get_timezone_offset( 'Europe/London', 'Asia/Shanghai' );
    
    // convert offset to hours
    echo $offset/3600;
    

    0 讨论(0)
提交回复
热议问题