AbsoluteDate to Java Instant

Hi all,
I have to save the data in a database including dates in UTC.
How can I obtain a Java Instant from an AbsoluteDate?
Thanks in advance.
Best regards

It is slightly complicated, especially if you want to preserve nanoseconds accuracy.
Here is one way to do it:

  long l = (long) FastMath.floor(date.offsetFrom(AbsoluteDate.JAVA_EPOCH, utc));
  long n = (long) FastMath.rint(date.durationFrom(new AbsoluteDate(AbsoluteDate.JAVA_EPOCH, l, utc)) * 1.0e9);
  Instant instant = Instant.ofEpochSecond(l, n);

We could probably add converters from/to Instant as we already have some for java.util.Date, this would involve less computation than the workaround above since we would have access to some private fields in AbsoluteDate. Could you open a feature request in our forge?


In fact I had problems with the accuracy.
I will try as you suggested.
Thanks Luc!
I will open the request in your forge as soon as my account is active.

1 Like

I created the issue: add converters AbsoluteDate from/to Instant (#1272) · Issues · Orekit / Orekit · GitLab.
Best regards