Here you can find the source of toDuration(Long unixTime)
public static String toDuration(Long unixTime)
//package com.java2s; //License from project: Open Source License import java.time.Duration; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.temporal.ChronoUnit; public class Main { public static String toDuration(Long unixTime) { LocalDateTime start = LocalDateTime.ofInstant(Instant.ofEpochSecond(unixTime), ZoneId.systemDefault()); LocalDateTime end = LocalDateTime.ofInstant(Instant.ofEpochSecond(0), ZoneId.systemDefault()); Duration duration = Duration.between(end, start); long hours = duration.toHours(); long minutes = duration.minusHours(hours).toMinutes(); return String.format("%02d:%02d", hours, minutes); }//from w w w .j a v a 2 s . c o m public static String toDuration(LocalDateTime start, LocalDateTime stop) { long hours = ChronoUnit.HOURS.between(start, stop); long minutes = ChronoUnit.MINUTES.between(start, stop) % 60; return String.format("%02d:%02d", hours, minutes); } }