tl;dr
Instant.ofEpochMilli( millisSinceJavaEpoch ) // Moment in UTC.
.atOffset( ZoneOffset.UTC ) // `OffsetDateTime` object.
.getLong( java.time.temporal.JulianFields.JULIAN_DAY ) // `long` such as 2457811.
java.time
Java 8 and later comes with the java.time classes, supplanting the troublesome old legacy date-time classes. See Oracle Tutorial.
"elapsed milliseconds since the beginning of the Unix Epoch"
If you mean the epoch of first moment of 1970 in UTC (1970-01-01T00:00:00Z
), then we can convert your count-of-milliseconds into a Instant
object. The Instant
class represents a moment on the timeline in UTC with a resolution of nanoseconds (up to nine (9) digits of a decimal fraction).
long millisSinceJavaEpoch = Instant.now().toEpochMilli() ; // Simulating your given number of milliseconds since 1970-01-01T00:00:00Z.
1488099298325
Instant instant = Instant.ofEpochMilli( millisSinceJavaEpoch ); // Convert from number to `Instant` object.
2017-02-26T08:54:58.325Z
We need a date from that Instant
. I'm no expert on Julian chronology, but it seems that by convention people use UTC in mapping to the modern ISO 8601 chronology. So let's convert that Instant
to a OffsetDateTime
with the offset constant ZoneOffset.UTC
.
OffsetDateTime odt = instant.atOffset( ZoneOffset.UTC ); // Convert from `Instant` to `OffsetDateTime` with UTC as assigned offset.
2017-02-26T08:54:58.325Z
From the OffsetDateTime
we can access a TemporalField
. As our implementation of TemporalField
we want JULIAN_DAY
constant from the java.time.temporal.JulianFields
class.
long jd = odt.getLong( java.time.temporal.JulianFields.JULIAN_DAY ); // Convert to Julian Day (number of whole days since January 1, 4713 BCE in the Julian calendar, a.k.a. -4713-11-24 Gregorian).
2457811
This result matches the result given at the web site you mentioned.
See this code above run live at IdeOne.com.
Depending on your definition, you may want MODIFIED_JULIAN_DAY
instead of JULIAN_DAY
.
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
- Java SE 8 and SE 9 and later
- Built-in.
- Part of the standard Java API with a bundled implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and SE 7
- Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
- Android
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, andfz more.
org.threeten.extra.chrono.JulianChronology
Those java.time classes are extended by the ThreeTen-Extra project. That project includes a proleptic implementation of the Julian calendar system, JulianChronology
.