وظيفة date_sunrise() في PHP

مثال

العودة إلى وقت شروق الشمس في شنغهاي، الصين اليوم:

<?php
// 上海,中国:
// 维度:北纬 31.22 ,经度:西经 121.47
// 天顶 ~= 90,偏移:+8 GMT
echo("上海,中国:日期:" . date("D M d Y"));
echo("<br>日出时间:");
echo(date_sunrise(time(),SUNFUNCS_RET_STRING,31.22,121.47,90,8));
?>

Run Example

Definition and Usage

The date_sunrise() function returns the sunrise time of the specified date and location.

Tip:See Also date_sunset() Function, returns the sunset time of the 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:

  • SUNFUNCS_RET_STRING (returns the result as a string, for example, 16:46) (default)
  • SUNFUNCS_RET_DOUBLE (returns the result as a floating-point number, for example, 16.78243132)
  • SUNFUNCS_RET_TIMESTAMP (returns the result as an integer (timestamp), for example, 1095034606)
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. 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 E_STRICT and E_NOTICE time zone errors when it occurs.