MENU
Sun Motion
date_sun_info($ts, $f1, $f2) returns an array with information about sunset/sunrise and twilight beginning/ending. $f1 and $f2 represent the latitude and longitude respectively. $f1 defaults to North; pass in a negative value for South. $f2 defaults to East; pass in a negative value for West. date_sunrise ($ts[,$i[,$f1[,$f2[,$f3[,$f4=0]]]]]) returns the sunrise time for a given day (specified as a timestamp $ts) and location. $i represents the return format, and it can be SUNFUNCS_RET_ STRING, SUNFUNCS_RET_DOUBLE, SUNFUNCS_ RET_TIMESTAMP. $f1, $f2 and $f3 represent the latitude, longitude and zenith respectively. $f4 is the GMT offset in hours. date_sunset(……) is similar to date_sunrise(……) but returns the sunset time instead. The three functions in this paragraph return FALSE on failure.<!DOCTYPE html><html><head></head>
<body><?php
date_default_timezone_set('Asia/Kuching');
$sun_info = date_sun_info(strtotime("2012-11-18"),
5.974, 116.069);
foreach ($sun_info as $key => $val) {
echo "$key: ".date("H:i:s",$val)."<br />";
}
echo date("D M d Y"). ', sunrise time : ' . date_sunrise(time(), SUNFUNCS_RET_STRING, 5.974, 116.069, 90, 8)."<br />";
echo date("D M d Y"). ', sunset time : ' . date_sunset(time(), SUNFUNCS_RET_STRING, 5.974, 116.069, 90, 8)."<br />";
?></body></html>sunrise: 06:04:37
sunset: 17:57:12
transit: 12:00:55
civil_twilight_begin: 05:43:46
civil_twilight_end: 18:18:03
nautical_twilight_begin: 05:18:18
nautical_twilight_end: 18:43:31
astronomical_twilight_begin: 04:52:52
astronomical_twilight_end: 19:08:57
Tue Sep 01 2026, sunrise time : 06:11
Tue Sep 01 2026, sunset time : 18:20
sunset: 17:57:12
transit: 12:00:55
civil_twilight_begin: 05:43:46
civil_twilight_end: 18:18:03
nautical_twilight_begin: 05:18:18
nautical_twilight_end: 18:43:31
astronomical_twilight_begin: 04:52:52
astronomical_twilight_end: 19:08:57
Tue Sep 01 2026, sunrise time : 06:11
Tue Sep 01 2026, sunset time : 18:20