date_sunrise


php apg

RETURNS the time of SUNRISE for a given day and location.


May experience difficulties in displaying characters outside of the English language when preceded with the setlocale function.


<?php

string
|int|float|false date_sunrise int $timestamp 
                                                       
int $returnFormat SUNFUNCS_RET_STRING 
                                             
float|null $latitude null 
                                             
float|null $longitude null 
                                             
float|null $zenith null 
                                             
float|null $utcOffset null )


where

$timestamp The timestamp of the day from which the sunrise time is taken

$returnFormat 
The constant to control the type of the result
                          
SEE the below TABLE )

$latitude The local LATITUDE
                  date
.default_latitude: as set in the php.ini

$longitude 
The local LONGITUDE
                    date
.default_longitude: as set in the php.ini

$zenith 
The angle between the center of the sun and a line 
               perpendicular to the surface of earth
               date
.sunrise_zenith: as set in the php.ini
               
SEE the below TABLE )

$utcOffset The GMT/UTC offset Specified in hours

?>

 $timestamp 


The timestamp of the day from which the sunrise time is taken.



 $returnFormat 

FORMAT CONSTANTS
CONSTANT VALUE RETURNED TYPE EXAMPLE
SUNFUNCS_RET_STRING 1 STRING 14:30
SUNFUNCS_RET_DOUBLE 2 FLOAT 14.5
SUNFUNCS_RET_TIMESTAMP 0 INTEGER TIMESTAMP
ed48


 $latitude 


The local LATITUDE or date.default_latitude: as set in the php.ini.



 $longitude 


The local LONGITUDE or date.default_longitude: as set in the php.ini.



 $zenith 

COMMON zenith ANGLES
ANGLE DESCRIPTION ABOUT
90°50' The point where the sun becomes invisible SUNSET
96° Conventionally used to signify the end of dusk CIVIL TWILIGHT
102° The point at which the horizon ends being visible at sea NAUTICAL TWILIGHT
108° The point at which the sun ends being the source of any illumination ASTRONOMICAL TWILIGHT
ed48

Accommodate yourself as a privileged observer, stationed at a given point on the earth plane.

Consider tracing a vertical line, perpendicular to that plane.

The point of the celestial sphere, above his head, intercepted by this line is called ZENITH.

Z apr

SOLAR ZENITH ANGLE is the angle formed by the vertical line at the point of the earth's surface where the observer is and the line of sight passing through the Sun.

Imagine, that same vertical, extended in the opposite direction.

The point that intercepts, analogously, the celestial sphere is called NADIR.

N apr

* Illustrations from WIKIPEDIA!



 $utcOffset 


The GMT/UCT offset specified in hours.





$utcOffset is specified in hours and is ignored, if $returnFormat is SUNFUNCS_RET_TIMESTAMP.

Every call to a date/time function will generate a E_NOTICE if the time zone is not valid, and/or a E_STRICT or E_WARNING message if using the system settings or the TZ environment variable.

See also date_default_timezone_set function.

This function returns the sunset time in a specified $returnFormat on success or FALSE on failure.

One potential reason for failure is that the sun does not set at all, which happens inside the polar circles for part of the year.

The values of date.default_latitude, date.default_longitude and date.sunrise_zenith are defined in the php.ini configuration file and should be changed if necessary.

Otherwise, the values of date.timezone, $latitude, $longitude, and $zenith must be supplied to the desired location.

D apr





The section of php.ini where this can be done is shown below:



[PHP]

; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =
date.timezone = 'America/Sao_Paulo'

; http://php.net/date.default-latitude
date.default_latitude = -23.5503948

; http://php.net/date.default-longitude
date.default_longitude = -46.634513

; http://php.net/date.sunrise-zenith
;date.sunrise_zenith = 90.583333

; http://php.net/date.sunset-zenith
;date.sunset_zenith = 90.583333

; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

  1 EXERCISE   

<?php

setlocale
(LC_ALL"pt_BR.utf-8""portuguese-brazil""ptb");
date_default_timezone_set('America/Sao_Paulo');

$in_gt  ini_get('date.timezone');
$df_lat ini_get('date.default_latitude');
$df_lng ini_get('date.default_longitude');
$df_dsz ini_get('date.sunset_zenith');
// Get the values defined in php.ini

echo 'INTERNAL PARAMETERS:<br><br>';

echo 
'Latitude: ' $df_lat .'<br>Longitude: ' $df_lng '<br>Zenith: ' $df_dsz;

$tstp gettimeofday(true);

echo 
'<br><br>DATE SUNRISE TYPE FORMATS:<br><br>';

echo 
'FLOAT<br>' $tstp '<br><br>';

// $sunrise_def = date_sunrise($tstp);
// echo 'STRING<br>' . $sunrise_def . '<br><br>';

$sunrise_str date_sunrise($tstpSUNFUNCS_RET_STRING);
echo 
'STRING<br>' $sunrise_str '<br><br>';

$sunrise_dbl date_sunrise($tstpSUNFUNCS_RET_DOUBLE);
echo 
'FLOAT<br>' $sunrise_dbl '<br><br>';

$sunrise_tm date_sunrise($tstpSUNFUNCS_RET_TIMESTAMP);
echo 
'INTEGER<br>' $sunrise_tm '<br><br>';

?> 

  2 EXERCISE   

<?php

setlocale
(LC_ALL"en_US""american""american english""american-english""english-american""english-us""english-usa""enu""us""usa"); 
date_default_timezone_set('America/New_York');

$tstp gettimeofday(true);

echo 
'<br>Central Park, New York, NY, USA<br><br>CURRENT TIMESTAMP:<br>' $tstp '<br><br>';

$lat 40.7828647;
$lng = -73.9675438;

$date date(DATE_W3C$tstp);

echo 
'CURRENT DATE:<br>' $date;

echo 
'<br><br>DATE SUNRISE TYPE FORMATS:';

$sunrise_str date_sunrise($tstpSUNFUNCS_RET_STRING$lat$lng);
echo 
'<br><br>STRING<br>' $sunrise_str '<br><br>';

$sunrise_dbl date_sunrise($tstpSUNFUNCS_RET_DOUBLE$lat$lng);
echo 
'FLOAT<br>' $sunrise_dbl '<br><br>';

$sunrise_tm date_sunrise($tstpSUNFUNCS_RET_TIMESTAMP$lat$lng);
echo 
'INTEGER<br>' $sunrise_tm;

?>