PHP date_sunset() Function
Example
Return the sunset time for Lisbon, Portugal today:
<?php // Shanghai, China: // Latitude: 31.22 North, Longitude: 121.47 West // Zenith ~= 90, Offset: +8 GMT echo("Shanghai, China: Date: " . date("D M d Y")); echo("<br>Time of sunrise:"); echo(date_sunrise(time(), SUNFUNCS_RET_STRING, 31.22, 121.47, 90, 8)); ?>
Definition and Usage
The date_sunset() function returns the sunset time for a specified date and location.
Tip:See also date_sunrise() Function, returns the sunrise time for a specified date and location.
Syntax
date_sunset(timestamp,format,latitude,longitude,zenith,gmtoffset);
Parameters | Description |
---|---|
timestamp | Required. Specifies the timestamp of the date and time to calculate the sunset time. |
format |
Optional. Specifies how to return the result:
|
latitude | Optional. Specifies the latitude of the location. The default is North latitude. To specify South latitude, please pass a negative value. |
longitude | Optional. Specifies the longitude of the location. The default is East longitude. To specify West longitude, please pass a negative value. |
zenith | Optional. The default is date.sunset_zenith. |
gmtoffset | Optional. Specifies the difference in hours between GMT and local time. |
Technical Details
Return Value: | If successful, it returns the sunset time in the specified format. If it fails, it returns FALSE. |
---|---|
PHP Version: | 5+ |
Update Log: | Starting from PHP 5.1.0, the function reports E_STRICT and E_NOTICE time zone errors when it occurs. |