PHP code example of nicolasleborgne / moon-phases-calculator
1. Go to this page and download the library: Download nicolasleborgne/moon-phases-calculator library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nicolasleborgne / moon-phases-calculator example snippets
use MoonPhaseCalculator\MoonPhaseCalculator;
/**
* Create a new calculator object,
* it takes a mandatory DateTime first parameter and an optionnal timezone parameter
*/
$moonPhasesCalculator = new MoonPhaseCalculator(
new DateTime("2016-11-16", new DateTimeZone('Europe/Paris')),
new DateTimeZone('Europe/Paris')
);
/**
* Call getMoonPhaseFromDateTime() method to get the moon phase
* associated to the dateTime given in param at the instanciation
*/
$moonPhase = $moonPhasesCalculator->getMoonPhaseFromDateTime();
/**
* You can also change the DateTime wich used for calcul
*/
$moonPhasesCalculator->setDateTime(new DateTime("2016-12-08", new DateTimeZone('Europe/Paris'));
/**
* To get directly the moon phase from the current date
*/
$moonPhasesCalculator->getCurrentMoonPhase();
/**
* To get moon phases date for the current synodic period
*/
$moonPhasesCalculator->getNewMoon();
$moonPhasesCalculator->getWaxingCrescent();
$moonPhasesCalculator->getFirstQuarter();
$moonPhasesCalculator->getWaxingGibbous();
$moonPhasesCalculator->getFullMoon();
$moonPhasesCalculator->getWaningGibbous();
$moonPhasesCalculator->getLastQuarter();
$moonPhasesCalculator->getWaningCrescent();