note 101170 added to function.date-sunrise
| From: | peter dot burden at gmail dot com | Date: | Tue, 30 Nov 2010 21:44:58 +0000 |
| Subject: | note 101170 added to function.date-sunrise | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174496@lists.php.net to get a copy of this message | ||
Care should be taken to ensure that time zones and daylight saving are handled correctly when using
these functions.
<?
$date = new DateTime('2010-12-21'); // Midwinter
$tz = new DateTimeZone("Europe/London");
$date->setTimezone($tz);
$date->setTime(12,0,0);
$t = $date->getTimestamp();
$respr = date_sunrise($t,SUNFUNCS_RET_STRING,52.58,-2.133);
$resps = date_sunset($t,SUNFUNCS_RET_STRING,52.58,-2.133);
echo date("c",$t) . "\n";
echo "Rise = " . $respr . " Set = " . $resps . "\n";
$date->setDate(2010,6,24); // Midsummer
$date->setTime(12,0,0);
$t = $date->getTimestamp();
$respr = date_sunrise($t,SUNFUNCS_RET_STRING,52.58,2.133);
$resps = date_sunset($t,SUNFUNCS_RET_STRING,52.58,2.133);
echo date("c",$t) . "\n";
echo "Rise = " . $respr . " Set = " . $resps . "\n";
?>
which produces the output below (lat/long are for Wolverhampton, England)
2010-12-21T12:00:00+00:00
Rise = 09:17 Set = 16:56
2010-06-24T12:00:00+01:00
Rise = 04:28 Set = 21:19
The figures for June are correct using daylight saving time, the figures for December are 1 hour
late, as if daylight saving time adjustment was still being applied. The two values of $t differ by
180 days and 1 hour as they should. Sunrise and sunset times checked using http://sunrise-sunset.dusk-dawn.com
----
Server IP: 87.124.126.138
Probable Submitter: 82.37.6.187 (proxied: 82.37.6.187)
----
Manual Page -- http://www.php.net/manual/en/function.date-sunrise.php
Edit -- https://master.php.net/note/edit/101170
Del: integrated -- https://master.php.net/note/delete/101170/integrated
Del: useless -- https://master.php.net/note/delete/101170/useless
Del: bad code -- https://master.php.net/note/delete/101170/bad+code
Del: spam -- https://master.php.net/note/delete/101170/spam
Del: non-english -- https://master.php.net/note/delete/101170/non-english
Del: in docs -- https://master.php.net/note/delete/101170/in+docs
Del: other reasons-- https://master.php.net/note/delete/101170
Reject -- https://master.php.net/note/reject/101170
Search -- https://master.php.net/manage/user-notes.php