PHP date_sunrise() Function
Example
Return the sunrise time for today in Shanghai, China:
<?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_sunrise() function returns the sunrise time at a specified date and location.
Tip:See also date_sunset() Function, returns the sunset time at a specified date and location.
Syntax
date_sunrise(timestamp,format,latitude,longitude,zenith,gmtoffset);
Parameters | Description |
---|---|
timestamp | Required. Specifies the timestamp of the date and time to calculate the sunrise time. |
format |
Optional. Specifies how to return the result:
|
latitude | Optional. Specifies the latitude of the location. Default is North Latitude. To specify South Latitude, please pass a negative value. |
longitude | Optional. Specifies the longitude of the location. Default is East Longitude. To specify West Longitude, please pass a negative value. |
zenith | Optional. Default is date.sunrise_zenith. |
gmtoffset | Optional. Specifies the difference between GMT and local time in hours. |
Technical Details
Return Value: | If successful, it returns the sunrise 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 time zone errors E_STRICT and E_NOTICE. |