Calculate the phase, distance, phase-angle, and illuminated ratio of the moon on any given date.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Build Status

Calculate the phase, distance, phase-angle, and illuminated ratio of the moon on any given date. Based on moonfx.bas from Sky & Telescope.


In root build.gradle:

	allprojects {
		repositories {
			maven { url '' }

In app build.gradle:

	dependencies {
		compile 'com.github.jesgs:moonfx:v1.0.1'


void setDate(LocalDateTime date) Sets the current date. Uses java.time.LocalDateTime

LocalDateTime getDate() Gets the current date in the form of a Date object

String getFormattedDate(String format) Returns a formatted date string, format specified by format parameter

double getSynodicPhase() Get current synodic phase of the moon, aka Moon's age in days (number of days from New Moon)

double getDistanceInEarthRadii() Get distance measured in Earth radii

double getEclipticLatitude() Get moon's ecliptic latitude

double getEclipticLongitude() Get moon's ecliptic longitude

double getJulianDate() Get the Julian Date for the date specified by setDate()

double getPhaseAngle(double synodicAge) Get the current approximate phase angle of the Moon. Uses value from getSynodicDate()

double getIlluminatedRatio(double synodicAge) Get Illuminated ratio of moon according to synodic age


MoonFx moonFx = new MoonFx();
moonFx.setDate(new Date()); // Thu Feb 09 17:25:26 CST 2017

System.out.println("Moon's age from new (days): " + moonFx.getSynodicPhase());
System.out.println("Distance (Earth radii): " + (int)moonFx.getDistanceInEarthRadii());
System.out.println("Distance (Miles): " + (int)(moonFx.getDistanceInEarthRadii() * MoonFx.EARTH_RADIUS_MI));


Moon's age from new (days): 12.945493872886475
Distance (Earth radii): 58
Distance (Miles): 231066


  • 1.1.0 — Current development version

    • Refactored Julian Date method
    • Refactored phase angle calculations
    • Refactored illuminated ratio calculations
    • Add unit tests
    • Add automated testing
  • 1.0.1 — Stable

    • Adjusted Julian Date calculation for better precision
  • 1.0.0

    • Initial release