date_sunrise

(PHP 5, PHP 7, PHP 8)

date_sunriseDevuelve la hora de la salida del sol de un día y ubicación dados

Descripción

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

date_sunrise() devuelve la hora de la salida del sol para un día (especificado como timestamp) y ubicación dados.

Parámetros

timestamp

La marca de tiempo timestamp del día del que se va a tomar la salida del sol.

format

Constantes format
constante descripción ejemplo
SUNFUNCS_RET_STRING devuelve el resultado como string 16:46
SUNFUNCS_RET_DOUBLE devuelve el resultado como float 16.78243132
SUNFUNCS_RET_TIMESTAMP devuelve el resultado como integer (timestamp) 1095034606

latitude

La latitud, por defecto a Norte, y como valor negativo a Sur. Vea también: date.default_latitude

longitude

La longitud, por defecto a Este, y como valor negativo a Oeste. Vea tambien: date.default_longitude

zenith

El cénit, por defecto: date.sunset_zenith

gmtoffset

El índice GMT especificado en horas.

Valores devueltos

Devuelve la hora de la salida del sol en un formato format especificado si se tuvo éxito o false en caso de error.

Errores/Excepciones

Cada vez que se llame a una función de fecha/hora se generará un E_NOTICE si la zona horaria no es válida, y/o un mensaje E_STRICT o E_WARNING si se emplea la configuración del sistema o la variable global TZ. Véase también date_default_timezone_set()

Historial de cambios

Versión Descripción
5.1.0

Ahora muestra un error E_STRICT y E_NOTICE cuando ocurren errores con zonas horarias.

Ejemplos

Ejemplo #1 Ejemplo de date_sunrise()

<?php

/* calcular la salida del sol para Lisboa, Portugal
Latitud: 38.4 Norte
Longitud: 9 Oeste
Cenit ~= 90
Índice: +1 GMT
*/

echo date("D M d Y"). ', hora de la salida del sol : ' .date_sunrise(time(), SUNFUNCS_RET_STRING, 38.4, -9, 90, 1);

?>

El resultado del ejemplo sería algo similar a:

Mon Dec 20 2004, hora de la salida del sol : 08:54

Ver también

  • date_sunset() - Devuelve la hora de la puesta de sol de un día y ubicación dados

add a note add a note

User Contributed Notes 3 notes

up
3
nomail at nospam dot com
5 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
4
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
-6
jonathanNO dot kuhnSPAM at gmailNOSPAM dot com
13 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