Documentación offline PHP master

DateTimeInterface::getOffset

master Ver versión oficial en línea Licencia CC-BY-3.0Descargado el 2026-08-02

En esta página

DateTimeInterface::getOffset

DateTimeImmutable::getOffset

DateTime::getOffset

date_offset_get

Devuelve el desplazamiento horario

Descripción#

Estilo orientado a objetos

public DateTimeInterface::getOffset(): int
```php

```php
public DateTimeImmutable::getOffset(): int
public DateTime::getOffset(): int
```php

Estilo procedimental

```php
date_offset_get(DateTimeInterface $object): int

Devuelve el desplazamiento horario.

Parámetros#

object
Solo en estilo procedimental: un objeto DateTime retornado por date_create

Valores devueltos#

Devuelve el desplazamiento horario en segundos, desde UTC en caso de éxito.

Ejemplos#

Ejemplo con DateTime::getOffset

Estilo orientado a objetos

<?php
$winter = new DateTimeImmutable('2010-12-21', new DateTimeZone('America/New_York'));
$summer = new DateTimeImmutable('2008-06-21', new DateTimeZone('America/New_York'));

echo $winter->getOffset() . "\n";
echo $summer->getOffset() . "\n";

El ejemplo anterior mostrará:

-18000
-14400

Estilo procedimental

<?php
$winter = date_create('2010-12-21', timezone_open('America/New_York'));
$summer = date_create('2008-06-21', timezone_open('America/New_York'));

echo date_offset_get($winter) . "\n";
echo date_offset_get($summer) . "\n";

El ejemplo anterior mostrará:

-18000
-14400

Nota: -18000 = -5 horas, -14400 = -4 horas.