选择语言 :

 Core_Date::offset

Returns the offset (in seconds) between two time zones. Use this to display dates to users in different time zones.

$seconds = Date::offset('America/Chicago', 'GMT');

A list of time zones that PHP supports can be found at

http://php.net/timezones.

integer Core_Date::offset( string $remote [, string $local = null , mixed $now = null ] )

参数列表

参数 类型 描述 默认值
$remote string Timezone that to find the offset of
$local string Timezone used as the baseline null
$now mixed UNIX timestamp or date string null
返回值
  • integer
File: ./core/classes/date.class.php
public static function offset($remote, $local = NULL, $now = NULL)
{
    if ( $local === NULL )
    {
        // Use the default timezone
        $local = date_default_timezone_get();
    }

    if ( is_int($now) )
    {
        // Convert the timestamp into a string
        $now = date(DateTime::RFC2822, $now);
    }

    // Create timezone objects
    $zone_remote = new DateTimeZone($remote);
    $zone_local = new DateTimeZone($local);

    // Create date objects from timezones
    $time_remote = new DateTime($now, $zone_remote);
    $time_local = new DateTime($now, $zone_local);

    // Find the offset
    $offset = $zone_remote->getOffset($time_remote) - $zone_local->getOffset($time_local);

    return $offset;
}