yes SUNFUNCS_RET_TIMESTAMP does return GMT(0) time
so something like...
$arr = localtime(date_sunset(time(),SUNFUNCS_RET_TIMESTAMP,51.5,0)); // London
$hh = $arr[2];
$mm = $arr[1];
Will give figure out your localtime and daylight saving (BST)
(PHP 5, PHP 7)
date_sunset — Returns time of sunset for a given day and location
$timestamp
[, int $format
= SUNFUNCS_RET_STRING
[, float $latitude
= ini_get("date.default_latitude")
[, float $longitude
= ini_get("date.default_longitude")
[, float $zenith
= ini_get("date.sunset_zenith")
[, float $gmt_offset
= 0
]]]]] )
date_sunset() returns the sunset time for a given
day (specified as a timestamp
) and location.
timestamp
The timestamp
of the day from which the sunset
time is taken.
format
constant | description | example |
---|---|---|
SUNFUNCS_RET_STRING | returns the result as string | 16:46 |
SUNFUNCS_RET_DOUBLE | returns the result as float | 16.78243132 |
SUNFUNCS_RET_TIMESTAMP | returns the result as integer (timestamp) | 1095034606 |
latitude
Defaults to North, pass in a negative value for South. See also: date.default_latitude
longitude
Defaults to East, pass in a negative value for West. See also: date.default_longitude
zenith
Default: date.sunset_zenith
gmtoffset
Specified in hours.
모든 날짜/시간 함수 호출은
시간대가 유효하지 않을 때 E_NOTICE
를, 시스템 설정이나
TZ 환경 변수를 사용할 때 E_STRICT
나
E_WARNING
메세지를
생성합니다. date_default_timezone_set()을
참고하십시오.
버전 | 설명 |
---|---|
5.1.0 | 시간대 오류시
|
Returns the sunset time in a specified format
on
success실패 시 FALSE
를 반환합니다.
Example #1 date_sunset() example
<?php
/* calculate the sunset time for Lisbon, Portugal
Latitude: 38.4 North
Longitude: 9 West
Zenith ~= 90
offset: +1 GMT
*/
echo date("D M d Y"). ', sunset time : ' .date_sunset(time(), SUNFUNCS_RET_STRING, 38.4, -9, 90, 1);
?>
위 예제의 출력 예시:
Mon Dec 20 2004, sunset time : 18:13
yes SUNFUNCS_RET_TIMESTAMP does return GMT(0) time
so something like...
$arr = localtime(date_sunset(time(),SUNFUNCS_RET_TIMESTAMP,51.5,0)); // London
$hh = $arr[2];
$mm = $arr[1];
Will give figure out your localtime and daylight saving (BST)
maybe I am wrong, but I think
SUNFUNCS_RET_TIMESTAMP return GMT(0) time
SUNFUNCS_RET_STRING Return local time
SUNFUNCS_RET_DOUBLE Return local time
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.
<?php
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";
}
?>