LocalDateTime Diff/Elapsed In Seconds

May 14, 2018
Duration.between(before, now).seconds
// get current utc time
val now = LocalDateTime.now(ZoneOffset.UTC)

// convert epoch seconds to LocalDateTime
val before = LocalDateTime.ofInstant(Instant.ofEpochSecond(seconds), ZoneOffset.UTC)

// compare diff in seconds between LocalDateTime
val seconds = Duration.between(before, now).seconds

NOTE: seconds shall be positive if now > before.

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.