solairs / php-moon-phase
在PHP中计算月相。
v3.1.0
2024-09-26 21:46 UTC
Requires
- php: >=8.2
Requires (Dev)
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^11.0
- rector/rector: ^1.0
- symplify/easy-coding-standard: ^12.0
README
Solaris PHP 月相
在PHP中计算月相。此库基于 Windows Moontool。
安装
此库是为与 Composer 一起使用而制作的。通过运行 $ composer require solaris/php-moon-phase 将它添加到您的项目中。
使用
创建一个 MoonPhase 类的实例,提供一个带有 UNIX 时间戳的 DateTime 对象,以确定您想计算的月相(如果不提供,则使用当前时间)。
然后您可以使用以下方法
getPhase():终止相角,以整个圆的分数表示(即,0到1)。两者都对应新月,而0.5对应满月。getIllumination():月亮被照亮的部分(0= 新月,1= 满月)。getAge():月亮的年龄,以天为单位。getDistance():月亮与地球中心的距离(公里)。getDiameter():月亮对地球中心观察者所形成的角直径(度)。getSunDistance():到太阳的距离(公里)。getSunDiameter():太阳对地球中心观察者所形成的角直径(度)。getPhaseNewMoon():当前月周期的新月时间,即当前周期的开始(UNIX 时间戳)。getPhaseNextNewMoon():下一个月周期的下一个新月时间,即下一个周期的开始(UNIX 时间戳)。getPhaseFullMoon():当前月周期的满月时间(UNIX 时间戳)。getPhaseNextFullMoon():下一个月周期的下一个满月时间(UNIX 时间戳)。getPhaseFirstQuarter():当前月周期的第一个季度时间(UNIX 时间戳)。getPhaseNextFirstQuarter():下一个月周期的下一个第一个季度时间(UNIX 时间戳)。getPhaseLastQuarter():当前月周期的最后一个季度时间(UNIX 时间戳)。getPhaseNextLastQuarter():下一个月周期的下一个最后一个季度时间(UNIX 时间戳)。getPhaseName():月相名称。
示例
<?php use Solaris\MoonPhase; $moonPhase = new MoonPhase(); $age = round($moonPhase->getAge(), 1); $stage = $moonPhase->getPhase() < 0.5 ? 'waxing' : 'waning'; $distance = round($moonPhase->getDistance(), 2); $next = gmdate('G:i:s, j M Y', (int) $moonPhase->getPhaseNextNewMoon()); echo 'The moon is currently ' . $age . ' days old, and is therefore ' . $stage . '. '; echo 'It is ' . $distance . ' km from the centre of the Earth. '; echo 'The next new moon is at ' . $next . '. ';
帮助
如果您有任何问题,请随时通过 hello@bitandblack.com 联系我们。
有关 Bit&Black 的更多信息,请参阅 www.bitandblack.com。