|
date_sunset
Returns time of sunset for a given day and location
(PHP 5)
Example 444. date_sunset() example<?php The above example will output something similar to: Mon Dec 20 2004, sunset time : 18:13 Code Examples / Notes » date_sunsetmichael
I use an IP to location database to determine the visitor's approximate latitude and longitude and then serve them a day or night color scheme based on whether it is before civil dawn or dusk. I've had problems when not specifying the timezone, specifically a 1 hour error, so I use GMT. <? date_default_timezone_set("GMT"); function scheme() { $sunrise = date_sunrise(time(), SUNFUNCS_RET_DOUBLE, $latitude, $longitude, 96, 0); $sunset = date_sunset(time(), SUNFUNCS_RET_DOUBLE, $latitude, $longitude, 96, 0); $now = date("H") + date("i") / 60 + date("s") / 3600; if ($sunrise < $sunset) if (($now > $sunrise) && ($now < $sunset)) return "day"; else return "night"; else if (($now > $sunrise) || ($now < $sunset)) return "day"; else return "night"; } ?> jbr
Here a function that will return an array of all valid formats, both starting and ending times! [Editor's note: you can find that function on the docpage of date_sunrise()] djwice
A way to use this: <?php // De Bilt, The Netherlands, weather station #06260 $lat = 52.10; // North $long = 5.18; // East $offset = 1; // difference between GMT and local time in hours $zenith=90+50/60; echo " Sunrise: ".date_sunrise(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset); echo " Sunset: ".date_sunset(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset); $zenith=96; echo " \"Civilian Twilight\" start: ".date_sunrise(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset); echo " \"Civilian Twilight\" end: ".date_sunset(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset); $zenith=102; echo " \"Nautical Twilight\" start: ".date_sunrise(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset); echo " \"Nautical Twilight\" end: ".date_sunset(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset); $zenith=108; echo " \"Astronomical Twilight\" start: ".date_sunrise(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset); echo " \"Astronomical Twilight\" end: ".date_sunset(time(), SUNFUNCS_RET_STRING, $lat, $long, $zenith, $offset); ?> Thanks to George King. More sources about this topic: http://www.qarlos.free.fr/navegacion/Sextante/formulas.htm http://williams.best.vwh.net/sunrise_sunset_algorithm.htm http://www.kevinboone.com/suntimes.html http://star-www.st-and.ac.uk/~fv/webnotes/chapt12.htm |
Change Languagecheckdate date_create date_date_set date_default_timezone_get date_default_timezone_set date_format date_isodate_set date_modify date_offset_get date_parse date_sun_info date_sunrise date_sunset date_time_set date_timezone_get date_timezone_set date getdate gettimeofday gmdate gmmktime gmstrftime idate localtime microtime mktime strftime strptime strtotime time timezone_abbreviations_list timezone_identifiers_list timezone_name_from_abbr timezone_name_get timezone_offset_get timezone_open timezone_transitions_get |