PHP | date_sunset()函数

date_sunset()是PHP中的一个内置函数,用于查找指定日期和位置的日落时间。

null

语法:

date_sunset ( $timestamp, $format, $latitude, $longitude, $zenith, $gmtoffset )

参数: 该函数接受上述四个参数,如下所述。

  • $timestamp: 它是一个必需的参数,用于指定日落时间从哪一天开始的时间戳。
  • $格式: 它是一个可选参数,指定返回结果的格式。返回格式如下:
    • SUNFUNCS_RET_STRING:返回一个字符串。e、 g.16:46(默认)
    • SUNFUNCS_RET_DOUBLE:返回浮点值。e、 g.16.12345
    • SUNFUNCS_RET_TIMESTAMP:将结果返回为整数(TIMESTAMP)。e、 g.987123569
  • $latitude: 它是一个可选参数,用于指定位置的纬度。默认情况下,它设置为“北”。要指定“南”的值,请传入负值。
  • $longitude: 它是一个可选参数,用于指定位置的经度。默认情况下,它设置为East。要修改West的值,请传入负值。
  • $zenith: 这是一个可选参数。这个 天顶 是太阳中心与垂直于地球表面的直线之间的角度,默认为 日期日落天顶 .
  • $gmtoffset: 它是可选参数,用于以小时为单位指定GMT和当地时间之间的差异。

返回值: 成功时,它以指定的格式返回日落时间。失败是错误的。

例外情况: 如果日期/时间函数无效,此函数将生成E_通知错误;如果使用系统设置或TZ环境变量,此函数将生成E_严格或E_警告。

下面的程序演示了PHP中的date_sunset()函数。

项目1:

<?php
// PHP program to show sunset time
// of New delhi india for current day
// Longitude and latitude of Delhi India
// 28.6139° N, 77.2090° E
// GMT(Greenwich Mean Time) +5.30
// Zenith ~= 90
echo date ( "D M d Y" );
echo ( "Sunset time: " );
echo (date_sunset(time(), SUNFUNCS_RET_STRING,
28.6139, 77.2090, 90, 5.30));
?>


输出:

Wed Jun 27 2018
Sunset time: 19:07

项目2:

<?php
// PHP program to show sunset time
// of GFG Noida for a Current day
// Longitude and latitude of GeeksforGeeks
// Noida 28°30'04.0"N 77°24'36.0"E
// GMT(Greenwich Mean Time) +5.30
// Zenith ~= 90
echo date ( "D M d Y" );
echo ( "Sunset time: " );
echo (date_sunset(time(), SUNFUNCS_RET_STRING,
28.501120, 77.409989, 90, 5.30));
?>


输出:

Wed Jun 27 2018
Sunset time: 19:06

相关文章:

参考: http://php.net/manual/en/function.date-sunset.php

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享