I\'ve got 2 Joda LocalDateTime
objects and need to produce a 3rd that represents the difference between them:
LocalDateTime start = getStartLoca
I found a workaround by using following steps:
start.toInstant(ZoneOffset.UTC);
Duration.between(instant t1, instant t2)
Duration.toNanos()
I have provided a full example below.
public long getDuration(LocalDateTime start, LocalDateTime end) {
//convert the LocalDateTime Object to an Instant
Instant startInstant = start.toInstant(ZoneOffset.UTC);
Instant endInstant = end.toInstant(ZoneOffset.UTC);
//difference between two Instants is calculated
//convert to nano seconds or milliseconds
long duration=Duration.between(startInstant, endInstant).toNanos();
return duration;
}