Home  >  Article  >  Backend Development  >  date_sunrise() function in PHP

date_sunrise() function in PHP

WBOY
WBOYforward
2023-09-09 11:01:021458browse

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.

Syntax

date_sunrise(timestamp,format,latitude,longitude,zenith,gmtoffset);

Parameters

  • 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).

Return

The date_sunrise() function returns the sunrise time in the specified format after success. FALSE on failure.

Example

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));
?>

Output

The following is the output-

Date: Wed Oct 10 2018
Sunrise time: 07:43

Example

Let’s see another example-

Live Demonstration

<?php
   $res = strtotime(&#39;2018-10-25&#39;);
   var_dump(date_sunrise($res, SUNFUNCS_RET_STRING, 69.245833, -53.537222));
?>

Output

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete