Instant
is still the best option, but you may need some helper objects.
For instance, to create the start date (replace the Z
with a different time zone or offset as needed):
Instant start = Instant.parse("1831-11-11T00:00:00Z");
Then take the given date. You can parse it, or use conversion methods. For instance, if you have a LocalDateTime
(use a different ZoneId
or ZoneOffset
as needed):
LocalDateTime localDateTime = LocalDateTime.parse("2022-06-09T20:56");
Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
Now get a duration:
Duration duration = Duration.between(start, instant);
long nanos = duration.toNanos();