Age of September 14, 1752
My reading of the Wikipedia page on the Calendar Act (New Style) 1750 indicates the date of the link to the era of 1752-09-14.
If we add the integer part of your input number 95906.27600694445 , 95_906L , we really get your target date on April 15, 2015 (in the modern calendar system).
long input = 95_906L; LocalDate epochCalendarNewStyleActOf1750 = LocalDate.of ( 1752 , Month.SEPTEMBER , 14 ); LocalDate localDate = epochCalendarNewStyleActOf1750.plusDays ( input ); System.out.println ( input + " days from epoch of: " + epochCalendarNewStyleActOf1750 + " is " + localDate );
95906 days from the era: 1752-09-14 - 2015-04-15
As for the fractional number, which I assume is the fraction of the number of seconds in the total 24-hour day.
While LocalDate refers only to a date - without a time of day, we need the time of day, which is represented by our fractional number. Therefore, instead of LocalDate we switch to OffsetDateTime .
OffsetDateTime epochCalendarNewStyleActOf1750 = LocalDate.of ( 1752 , Month.SEPTEMBER , 14 ).atStartOfDay ().atOffset ( ZoneOffset.UTC );
We use BigDecimal as a double and double floating point technology that eliminates precision for execution speed.
String input = "95906.27600694445"; BigDecimal bd = new BigDecimal ( input );
Get the number of whole days out of it.
long days = bd.toBigInteger ().longValue ();
Work on a fraction of the day. Extract the fractional number by subtracting the integer part.
BigDecimal fractionOfADay = bd.subtract ( new BigDecimal ( days ) );
We assume that this decimal is part of the number of seconds per day. Thus, we can multiply by the number of seconds - this is the day.
BigDecimal secondsFractional = new BigDecimal ( TimeUnit.DAYS.toSeconds ( 1 ) ).multiply ( fractionOfADay );
Extract the number of whole seconds. From the remainder, produce an integer number of nanoseconds, resolving the java.time classes, including OffsetDateTime and Duration .
long secondsWhole = secondsFractional.longValue (); long nanos = secondsFractional.subtract ( new BigDecimal ( secondsWhole ) ).multiply ( new BigDecimal ( 1_000_000_000L ) ).longValue ();
Create a Duration to represent the amount of time we want to add to our era.
Duration duration = Duration.ofDays ( days ).plusSeconds ( secondsWhole ).plusNanos ( nanos );
Add duration to the era to get the final result.
OffsetDateTime odt = epochCalendarNewStyleActOf1750.plus ( duration );
You can retrieve the Instant object from OffsetDateTime .
Instant instant = odt.toInstant();
Dump for the console.
System.out.println ( "bd: " + bd ); System.out.println ( "days: " + days ); System.out.println ( "fractionOfADay.toString(): " + fractionOfADay ); System.out.println ( "secondsFractional: " + secondsFractional ); System.out.println ( "secondsWhole: " + secondsWhole ); System.out.println ( "nanos: " + nanos ); System.out.println ( "duration.toString(): " + duration ); System.out.println ( "duration.toDays(): " + duration.toDays () ); System.out.println ( "odt.toString(): " + odt );
This code is working correctly. The result here corresponds to the expectation specified in the Question, the second, although we do not agree with a split second.
There are no guarantees; this code is fresh from my head and is quite untested and unproven.
See this code run on IdeOne.com .
bd: 95906.27600694445
days: 95906
fractionOfADay.toString (): 0.27600694445
secondsFractional: 23847.00000048000
secondsWhole: 23847
nanos: 480
duration.toString (): PT2301750H37M27.00000048S
duration.toDays (): 95906
odt.toString (): 2015-04-15T06: 37: 27.000000480Z
Of course, this math could be simpler. But I thought it would be interesting to show the pieces. One simple way is to multiply 95906.27600694445 BigDecimal by the number of seconds in a total 24-hour day. Then, separate the resulting integer from its decimal and feed each to Duration.ofSeconds and Duration::plusNanos , as it corresponds to the Duration internal data model, the total number of seconds and the total number of nano in a split second. We would skip the part where we called Duration.ofDays .
About java.time
The java.time framework is built into Java 8 and later. These classes supersede the nasty old legacy time classes such as java.util.Date , Calendar and SimpleDateFormat .
The Joda-Time project, now in maintenance mode , we recommend switching to the java.time classes.
To learn more, see the Oracle Tutorial . And search for qaru for many examples and explanations. JSR 310 specification .
Where to get java.time classes?
- Java SE 8 and SE 9 and later
- Built in.
- Part of the standard Java API with integrated implementation.
- Java 9 adds some minor features and fixes.
- Java SE 6 and SE 7
- Most of the functionality of java.time is ported back to Java 6 and 7 in ThreeTen-Backport .
- Android
The ThreeTen-Extra project extends java.time with additional classes. This project is proof of possible future additions to java.time. Here you can find useful classes such as Interval , YearWeek , YearQuarter and more .