This post shows you how to convert nanoseconds and seconds to days hours minutes using java 8 LocalTime API.
LocalTime API contains
public static LocalTime ofNanoOfDay(long nanoOfDay)
Obtains an instance of LocalTime from a nanos-of-day value.
public static LocalTime ofSecondOfDay(long secondOfDay)
Obtains an instance of LocalTime from a second-of-day value.
Example
import java.time.Clock; import java.time.LocalTime; import java.time.ZoneId; public class LocalTimeExample { public static void main(String[] args) { // converts no of seconds of the day to time LocalTime secOfDay = LocalTime.ofSecondOfDay(10160); System.out.println("seconds of the day: "+secOfDay); LocalTime nantoDay = LocalTime.ofNanoOfDay(10160000000000l); System.out.println("seconds of the day: "+nantoDay); } }
Output:
seconds of the day: 02:49:20
seconds of the day: 02:49:20