English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
date_sunset()函数返回给定日期/地点的日落时间。
date_sunset()函数接受表示给定一天的时间戳,并返回该特定日期的日落时间。
date_sunset($timestamp, [$format, $latitude, $longitude, $zenith, $gmtoffset])
序号 | 参数及说明 |
---|---|
1 | timestamp (必需) 这指定一个时间戳。 |
2 | format (可选) 这指定了您需要使用结果值的格式。您可以传递三个常量作为该参数的值; SUNFUNCS_RET_STRING(,, Integer. |
3 | latitude (optional) By default, this option specifies the latitude of a location, which specifies the north direction. To specify the latitude value of the south, it must be passed as a negative value. |
4 | longitude (optional) By default, it specifies the longitude of a location, which specifies the east direction. To specify the longitude value of the west, it must be passed as a negative value. |
5 | zenith (optional) This specifies the zenith value. This specifies the angle between the line perpendicular to the Earth's surface and the center of the sun. |
6 | gmtoffset (optional) This specifies the time difference between GMT and local time (in hours). |
The date_sunset() function returns the sunset time in the required format. If it fails, it will return a boolean valuefalse.
This function was originally introduced in PHP 5. Introduced in version 0.0 and available in all higher versions.
The following example demonstratesdate_sunset()Function usage-
<?php $sun_info = date_sunset("02-17-2012"); print_r($sun_info); ?>Test and see‹/›
Output result
14:46
Now, to call this function, you must pass the latitude and longitude values. If you want to pass latitude and longitude values, you must also pass the required format values-
<?php $sun_info = date_sunset("02-03-2020", SUNFUNCS_RET_STRING, 23.4, -25); print_r("Sunset Time: ".$sun_info); ?>Test and see‹/›
Output result
Sunset Time: 19:05
The following example verifies the case without sunset-
<?php $sun_info = date_sunset("25-12-2016", SUNFUNCS_RET_STRING, 69, 41); print("Sunset Time: ".$sun_info); print("\n"); var_dump($sun_info); ?>Test and see‹/›
Output result
Sunset Time: bool(false)
<?php echo("Date: ".date("D M d Y")); echo("\n"); echo("Sunset time: "); echo(date_sunset(time(), SUNFUNCS_RET_STRING,38.4,-9,90,1)); ?>Test and see‹/›
Output result
Date: Thu May 07 2020 Sunset time: 20:30