note 101170 modified in function.date-sunrise by danbrown
| From: | danbrown@php.net | Date: | Tue, 30 Nov 2010 21:46:44 +0000 |
| Subject: | note 101170 modified in function.date-sunrise by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174497@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.
<?php
$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
--was--
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
http://php.net/manual/en/function.date-sunrise.php