PHP 8.4.1 Released!

DateTimeInterface::getOffset

DateTimeImmutable::getOffset

DateTime::getOffset

date_offset_get

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

DateTimeInterface::getOffset -- DateTimeImmutable::getOffset -- DateTime::getOffset -- date_offset_getReturns the timezone offset

Descrizione

Stile orientato agli oggetti

public DateTimeInterface::getOffset(): int
public DateTimeImmutable::getOffset(): int
public DateTime::getOffset(): int

Stile procedurale

Returns the timezone offset.

Elenco dei parametri

oggetto

Solo per lo stile procedurale: Un oggetto DateTime restituito da date_create()

Valori restituiti

Returns the timezone offset in seconds from UTC on success.

Esempi

Example #1 DateTime::getOffset() example

Stile orientato agli oggetti

<?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";
?>

Stile procedurale

<?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";
?>

I precedenti esempi visualizzeranno:

-18000
-14400

Note: -18000 = -5 hours, -14400 = -4 hours.

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top