date_sunrise

(PHP 5, PHP 7, PHP 8)

date_sunrise 指定した日付と場所についての日の出時刻を返す

警告

この関数は PHP 8.1.0 で 非推奨 になります。 この機能に頼らないことを強く推奨します。 代わりに date_sun_info() を使ってください。

説明

date_sunrise(
    int $timestamp,
    int $returnFormat = SUNFUNCS_RET_STRING,
    ?float $latitude = null,
    ?float $longitude = null,
    ?float $zenith = null,
    ?float $utcOffset = null
): string|int|float|false

date_sunrise() は、与えられた日付 (timestamp で指定する) と場所についての日の出の時刻を返します。

パラメータ

timestamp

日の出時刻を取得する日の timestamp

returnFormat

returnFormat 定数
定数 説明
SUNFUNCS_RET_STRING 結果を string で返します。 16:46
SUNFUNCS_RET_DOUBLE 結果を float で返します。 16.78243132
SUNFUNCS_RET_TIMESTAMP 結果を int (タイムスタンプ) で返します。 1095034606

latitude

デフォルトは北緯で、南緯は負の値で表します。 date.default_latitude も参照ください。

longitude

デフォルトは東経で、西経は負の値で表します。 date.default_longitude も参照ください。

zenith

zenith は 太陽の中心と、地球の表面からの垂線の間になす角度です。 デフォルトは date.sunrise_zenith です。

一般的な zenith の角度
角度 説明
90°50' 日の出: 太陽が見えるようになる点
96° 薄明かり: 夜明けの始まりを示すのに慣習的に使われます
102° 航海上の薄明かり: 海の上で、水平線が見えはじめる点
108° 天文学上の薄明かり: 太陽があらゆる明かりの光源になりはじめる点

utcOffset

時間単位で指定します。 returnFormatSUNFUNCS_RET_TIMESTAMP の場合は、 utcOffset は無視されます。

戻り値

日の出時刻を、指定した returnFormat で返します。 失敗した場合に false を返します。 失敗する潜在的な可能性があります。太陽が全く昇らない場合です。 これは一年のある時期、極圏の中にある場合に起こります。

エラー / 例外

すべての日付/時刻関数は、 有効なタイムゾーンが設定されていない場合に E_WARNING を発生させます。 date_default_timezone_set() も参照ください。

変更履歴

バージョン 説明
8.1.0 この関数は、推奨されなくなりました。 date_sun_info() を代わりに使って下さい。
8.0.0 latitude, longitude, zenith, utcOffset は、nullable になりました。

例1 date_sunrise() の例

<?php

/* ポルトガル リスボンの日の出時刻を計算する
緯度: 北緯 38.4
経度: 西経 9
天頂 ~= 90
時差: +1 GMT
*/

echo date("D M d Y"). ', sunrise time : ' .date_sunrise(time(), SUNFUNCS_RET_STRING, 38.4, -9, 90, 1);

?>

上の例の出力は、 たとえば以下のようになります。

Mon Dec 20 2004, sunrise time : 08:54

例2 No sunrise

<?php
$solstice
= strtotime('2017-12-21');
var_dump(date_sunrise($solstice, SUNFUNCS_RET_STRING, 69.245833, -53.537222));
?>

上の例の出力は以下となります。

bool(false)

参考

  • date_sun_info() - 日の出/日の入り時刻と薄明かり (twilight) の開始/終了時刻の情報を含む配列を返す

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