DateTime::getOffset

DateTimeImmutable::getOffset

DateTimeInterface::getOffset

date_offset_get

(PHP 5 >= 5.2.1, PHP 7)

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

Descrierea

Stil obiect-orientat

publicDateTime::getOffset ( ) : int
publicDateTimeImmutable::getOffset ( ) : int
publicDateTimeInterface::getOffset ( ) : int

Stil procedural

Returns the timezone offset.

Parametri

object

Doar pentru stilul procedural: Un obiect DateTime întors de funcția date_create()

Valorile întoarse

Returns the timezone offset in seconds from UTC on success.

Istoricul schimbărilor

Versiune Descriere
8.0.0 Prior to this version, false was returned on failure.

Exemple

Example #1 DateTime::getOffset() example

Stil obiect-orientat

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

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

Stil procedural

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

Exemplele de mai sus vor afișa:

-18000
-14400

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

add a note add a note

User Contributed Notes 1 note

up
0
s7sunder at gmail dot com
10 years ago
This will be useful for converting offset values into GMT format

<?php

 
//target time zone
 
$target_time_zone = new DateTimeZone('America/Los_Angeles');

 
//find kolkata time
 
$kolkata_date_time = new DateTime('now', $target_time_zone);
 
 
//get the exact GMT format
 
echo 'GMT '.$kolkata_date_time->format('P');
To Top