Short answer:
LocalDate date = LocalDate.now(); long modifiedJulianDay = date.getLong(JulianFields.MODIFIED_JULIAN_DAY);
Explanation:
Wikipedia gives a better description of Julian as a concept. Simply put, this is a simple, continuous number of days from a certain era, where the chosen era gives variations its name. Thus, Modified Julian Day totals 1858-11-17.
JSR-310 date and time objects implement the TemporalAccessor interface, which defines the get(TemporalField) and getLong(TemporalField) methods. They allow you to query a date / time object for a specific period of time. There are four field implementations that offer Julian day options:
These fields can only be used with getLong(TemporalField) , because they return a number that is too large for int . If you call now.get(JulianFields.MODIFIED_JULIAN_DAY) then an exception will be thrown: "UnsupportedTemporalTypeException: invalid ModifiedJulianDay field for get () method, use getLong () instead
Please note that JSR-310 can only provide integers from TemporalField , so the time of day cannot be represented, and all numbers are based on midnight. The calculations also use the local midnight, not UTC, which should be considered.
Fields can also be used to update a date / time object using the Temporal method:
result = input.with(JulianFields.MODIFIED_JULIAN_DAY, 56685);
source share