Class JulianDate
- All Implemented Interfaces:
Serializable,Cloneable
The Julian day or Julian day number (JDN) is the (integer) number of days that have elapsed since Monday, January 1, 4713 BC in the proleptic Julian calendar 1. That day is counted as Julian day zero. Thus the multiples of 7 are Mondays. Negative values can also be used.
The Julian Date (JD) is the number of days (with decimal fraction of the day) that have elapsed since 12 noon Greenwich Mean Time (UT or TT) of that day. Rounding to the nearest integer gives the Julian day number.
For calculations that will have time precision of 1e-3 seconds, both fraction and integer part must have enough digits in it. The problem is that integer part is big and, on the other hand fractional is small, and since final Julian date is a sum of this two values, some fraction numerals may be lost. Therefore, for higher precision both fractional and integer part of Julian date real number has to be preserved.
This class stores the unmodified fraction part, but not all digits are significant! For 1e-3 seconds precision, only 8 digits after the decimal point are significant.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected doubleFraction part of the Julian Date (JD).protected intInteger part of the Julian Date (JD).static final JulianDateJulian Date for 1970-01-01T00:00:00 (Thursday).static final JulianDateJulian Date for 2001-01-01T00:00:00 (Monday).private static final JulianDateJulian Date when Modified Julian Date (MJD) is 0.private static final JulianDateJulian Date when Reduced Julian Date (RJD) is 0.private static final JulianDateJulian Date when Truncated Julian Date (TJD) is 0. -
Constructor Summary
ConstructorsConstructorDescriptionJulianDate(int i, double f) Creates JD from both integer and fractional part using normalization. -
Method Summary
Modifier and TypeMethodDescriptionadd(double delta) Adds a double delta value and returns a new instance.add(JulianDate jds) Adds two JD and returns a new instance.protected JulianDateclone()intdaysBetween(JulianDate otherDate) Calculates the number of days between two dates.intdaysSpan(JulianDate otherDate) Returns span between two days.booleanstatic JulianDatefromModifiedJulianDate(double mjd) Returns the JD from a Modified Julian Date (MJD), where date starts from midnight rather than noon.static JulianDatefromReducedJulianDate(double rjd) Returns the JD from a Reduced Julian Date (RJD), used by astronomers.static JulianDatefromTruncatedJulianDate(double tjd) Returns the JD from a Truncated Julian Day (TJD), introduced by NASA for the space program.doubleReturns the fraction part of Julian Date (JD).intReturns integer part of the Julian Date (JD).intReturns JDN.Returns Modified Julian Date (MJD), where date starts from midnight rather than noon.Returns Reduced Julian Date (RJD), used by astronomers.intCalculates and returns significant fraction only as an int.Returns Truncated Julian Day (TJD), introduced by NASA for the space program.inthashCode()static JulianDatenow()static JulianDateof(double jd) Creates JD from a double value.static JulianDateof(int i, double f) static JulianDateof(int year, int month, int day, int hour, int minute, int second, int millisecond) static JulianDateof(long milliseconds) static JulianDateof(BigDecimal bd) static JulianDatestatic JulianDatestatic JulianDateof(LocalDateTime localDateTime) sub(double delta) Subtracts a double from current instance and returns a new instance.sub(JulianDate jds) Subtracts a JD from current instance and returns a new instance.ReturnsBigDecimalvalue of JD.doubletoDouble()Returnsdoublevalue of JD.Converts to Instant.Converts to LocalDateTime at UTC.longConverts to milliseconds.toString()Returns string representation of JD.
-
Field Details
-
JD_1970
Julian Date for 1970-01-01T00:00:00 (Thursday). -
JD_2001
Julian Date for 2001-01-01T00:00:00 (Monday). -
JD_RJD_0
Julian Date when Reduced Julian Date (RJD) is 0. RJD = JD − 2400000 -
JD_MJD_0
Julian Date when Modified Julian Date (MJD) is 0. MJD = JD − 2400000.5 -
JD_TJD_0
Julian Date when Truncated Julian Date (TJD) is 0. TJD began at midnight at the beginning of May 24, 1968 (Friday). -
integer
protected int integerInteger part of the Julian Date (JD). -
fraction
protected double fractionFraction part of the Julian Date (JD). Should be always in [0.0, 1.0) range.
-
-
Constructor Details
-
JulianDate
public JulianDate(int i, double f) Creates JD from both integer and fractional part using normalization. Normalization means that if fractional part is out of range, values will be correctly fixed.- Parameters:
i- integer partf- fractional part should be in range [0.0, 1.0)
-
-
Method Details
-
of
Creates JD from a double value. CAUTION: double values may not be suited for precision math. If precision is needed, consider passing in a BigDecimal instead. -
of
-
of
-
of
-
of
-
of
-
of
public static JulianDate of(int year, int month, int day, int hour, int minute, int second, int millisecond) -
of
-
now
-
getInteger
public int getInteger()Returns integer part of the Julian Date (JD). -
getFraction
public double getFraction()Returns the fraction part of Julian Date (JD). Returned value is always in [0.0, 1.0) range. -
getSignificantFraction
public int getSignificantFraction()Calculates and returns significant fraction only as an int. -
getJulianDayNumber
public int getJulianDayNumber()Returns JDN. Note that JDN is not equal tointeger. It is calculated by rounding to the nearest integer. -
toDouble
public double toDouble()Returnsdoublevalue of JD. CAUTION: double values may not be suited for precision math due to loss of precision. -
toBigDecimal
ReturnsBigDecimalvalue of JD. -
toString
Returns string representation of JD. -
toMilliseconds
public long toMilliseconds()Converts to milliseconds. -
toInstant
Converts to Instant. -
toLocalDateTime
Converts to LocalDateTime at UTC. -
add
Adds two JD and returns a new instance. -
add
Adds a double delta value and returns a new instance. -
sub
Subtracts a JD from current instance and returns a new instance. -
sub
Subtracts a double from current instance and returns a new instance. -
daysBetween
Calculates the number of days between two dates. Returned value is always positive. -
daysSpan
Returns span between two days. Returned value may be positive (when this date is after the provided one) or negative (when comparing to future date). -
equals
-
hashCode
public int hashCode() -
clone
-
getReducedJulianDate
Returns Reduced Julian Date (RJD), used by astronomers. RJD = JD − 2400000 -
getModifiedJulianDate
Returns Modified Julian Date (MJD), where date starts from midnight rather than noon. MJD = JD − 2400000.5 -
getTruncatedJulianDate
Returns Truncated Julian Day (TJD), introduced by NASA for the space program. TJD began at midnight at the beginning of May 24, 1968 (Friday). -
fromReducedJulianDate
Returns the JD from a Reduced Julian Date (RJD), used by astronomers. RJD = JD − 2400000 -
fromModifiedJulianDate
Returns the JD from a Modified Julian Date (MJD), where date starts from midnight rather than noon. MJD = JD − 2400000.5 -
fromTruncatedJulianDate
Returns the JD from a Truncated Julian Day (TJD), introduced by NASA for the space program. TJD began at midnight at the beginning of May 24, 1968 (Friday).
-