php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #63415 Code example incorrect
Submitted: 2012-11-01 23:45 UTC Modified: 2012-11-04 23:13 UTC
From: mike at mikehoward dot com dot au Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: not relevant
Private report: No CVE-ID: None
 [2012-11-01 23:45 UTC] mike at mikehoward dot com dot au
Description:
------------
---
From manual page: http://www.php.net/datetimezone.getoffset#refsect1-
datetimezone.getoffset-examples
---

The example for getOffset says:
// Calculate the GMT offset for the date/time contained in the $dateTimeTaipei
// object, but using the timezone rules as defined for Tokyo
// ($dateTimeZoneJapan).
$timeOffset = $dateTimeZoneJapan->getOffset($dateTimeTaipei);

This is not correct. You can't pass a DateTime object when used this way.

Test script:
---------------
// This is not a test script - this is a suggestion to replace the current example

// Create a timezone object
$dateTimeZoneSyd = new DateTimeZone("Australia/Sydney");

// Create a DateTime object (it's daylight savings time now - 2012-11-02)
$dateTimeSydney = new DateTime("now", $dateTimeZoneSyd);

// Calculate the GMT offset for the date/time contained in the object

$timeOffset = $dateTimeSydney->getOffset();

// Should show int(39600).
var_dump($timeOffset);



Patches

new-DateTime-getOffset-example (last revision 2012-11-01 23:46 UTC by mike at mikehoward dot com dot au)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-03 00:44 UTC] mail+php at requinix dot net
I think you're confused. There are two getOffset() methods: one in DateTimeZone 
which requires a DateTime argument, and another in DateTime which takes no 
arguments.

The example you're quoting works fine for me (5.3.10).
 [2012-11-04 23:13 UTC] mike at mikehoward dot com dot au
-Status: Open +Status: Closed
 [2012-11-04 23:13 UTC] mike at mikehoward dot com dot au
I'm sorry - I was using the getOffset method of a DateTime object - thanks for the 
quick response.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 19:00:01 2026 UTC