date_sunrise

(PHP 5, PHP 7, PHP 8)

date_sunriseRetorna a hora do nascer do sol de um dia e localicação informada

Descrição

date_sunrise ( int $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.

Parâmetros

timestamp

O timestamp do nascer do sol do dia desejado.

format

constantes de 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.

Valor Retornado

Retorna a hora do nascer do sol no format especificado em caso de sucesso ou false em caso de falha.

Erros

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()

Changelog

Versão Descrição
5.1.0

Agora lança erros E_STRICT e E_NOTICE .

Exemplos

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_STRING38.4, -9901);

?>

O exemplo acima irá imprimir algo similar à:

Mon Dec 20 2004, sunrise time : 08:54

Veja Também

  • date_sunset() - Retorna a hora do pôr do sol de um dia e localização informada.

add a note add a note

User Contributed Notes 3 notes

up
3
nomail at nospam dot com
6 years ago
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
up
3
scottix at gmail dot com
10 years ago
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
);
up
-4
jonathanNO dot kuhnSPAM at gmailNOSPAM dot com
14 years ago
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
To Top