Home > Article > Backend Development > date_sunrise() function in PHP
date_sunrise() function returns the sunrise time for a given date/location. If successful, it will return the sunrise time in the specified format. FALSE on failure.
date_sunrise(timestamp,format,latitude,longitude,zenith,gmtoffset);
Timestamp - Get the timestamp of the current day at sunrise time.
format - Specifies how to return the result:
SUNFUNCS_RET_STRING: Returns the result as a string.
SUNFUNCS_RET_DOUBLE: Returns the result in floating point form.
SUNFUNCS_RET_TIMESTAMP: Returns the result as an integer (timestamp)
Latitude - specified The latitude of the location. Latitude defaults to North. If you want to specify a south value, you must pass a negative value.
Longitude - The longitude of the specified location. Longitude defaults to east longitude. If you want to specify a west value, you must pass a negative value.
zenith - Defaults to date.sunrise_zenith
li>gmtoffset - Between GMT and local time time difference (in hours).
The date_sunrise() function returns the sunrise time in the specified format after success. FALSE on failure.
The following is an example-
Live demonstration
<?php echo("Date: " . date("D M d Y") . "<br />"); echo("Sunrise time: "); echo(date_sunrise(time(),SUNFUNCS_RET_STRING,38.4,-9,90,1)); ?>
The following is the output-
Date: Wed Oct 10 2018 Sunrise time: 07:43
Let’s see another example-
Live Demonstration
<?php $res = strtotime('2018-10-25'); var_dump(date_sunrise($res, SUNFUNCS_RET_STRING, 69.245833, -53.537222)); ?>
Here is the output-
string(5) "11:28"
The above is the detailed content of date_sunrise() function in PHP. For more information, please follow other related articles on the PHP Chinese website!