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');
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
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;
}