maybe I am wrong, but I think
SUNFUNCS_RET_TIMESTAMP return GMT(0) time
SUNFUNCS_RET_STRING Return local time
SUNFUNCS_RET_DOUBLE Return local time
(PHP 5, PHP 7, PHP 8)
date_sunrise — Retorna a hora do nascer do sol de um dia e localicação informada
$timestamp
, int $format
= SUNFUNCS_RET_STRING
, float $latitude
= ini_get("date.default_latitude")
, float $longitude
= ini_get("date.default_longitude")
, float $zenith
= ini_get("date.sunrise_zenith")
, float $gmt_offset
= 0
) : mixed
A função date_sunrise() retorna a hora do nascer do sol de um
dia (especificado como um timestamp
) e localização informada.
timestamp
O timestamp
do nascer do sol do dia
desejado.
format
constante | descrição | exemplo |
---|---|---|
SUNFUNCS_RET_STRING | retorna o resultado como uma string | 16:46 |
SUNFUNCS_RET_DOUBLE | retorna o resultado como um float | 16.78243132 |
SUNFUNCS_RET_TIMESTAMP | retorna o resultado como um integer (timestamp) | 1095034606 |
latitude
Padronizado ao Norte, passe o valor negativado para Sul.
Veja também: date.default_latitude
longitude
Padronizado a Leste, passe o valor negativado para Oeste.
Veja também: date.default_longitude
zenith
Padrão: date.sunrise_zenith
gmtoffset
Especificado em horas.
Retorna a hora do nascer do sol no format
especificado em caso de
sucesso ou false
em caso de falha.
Todas as chamadas a funções de data/hora gerarão um E_NOTICE
se o fuso horário não for válido, e/ou uma mensagem E_STRICT
ou E_WARNING
se utilizar as configurações do sistema ou a variável de ambiente
TZ. Veja também date_default_timezone_set()
Versão | Descrição |
---|---|
5.1.0 |
Agora lança erros |
Exemplo #1 Exemplo da função date_sunrise()
<?php
/* calculate the sunrise time for Lisbon, Portugal
Latitude: 38.4 North
Longitude: 9 West
Zenith ~= 90
offset: +1 GMT
*/
echo date("D M d Y"). ', sunrise time : ' .date_sunrise(time(), SUNFUNCS_RET_STRING, 38.4, -9, 90, 1);
?>
O exemplo acima irá imprimir algo similar à:
Mon Dec 20 2004, sunrise time : 08:54
maybe I am wrong, but I think
SUNFUNCS_RET_TIMESTAMP return GMT(0) time
SUNFUNCS_RET_STRING Return local time
SUNFUNCS_RET_DOUBLE Return local time
If you are working in multiple timezones getting the offset from a date is a little tricky because you need it in hours.
<?php
$time = new DateTime('now', new DateTimeZone('America/Los_Angeles'));
date_sunrise(
$time->getTimestamp(),
SUNFUNCS_RET_TIMESTAMP,
38.4,
-9,
90,
$time->getOffset() / 3600
);
After some searching, I finally found a website that can calculate the sun's zenith. Just look up your city's lat/long (remember, west/south are negative even if it doesn't show where you look up the lat/long) and the time of sunrise/sunset and use this site:
http://solardat.uoregon.edu/cgi-bin/SolarPositionCalculator.cgi
You have to enter in the sunrise/sunset times separately, but it works.
San Diego is:
Lat: 32.73
Long: -117.17
Sunrise Z.: 90.7379
Sunset Z.: 90.8880