Here you can find the source of toSeconds(long duration, TimeUnit timeUnit)
public static int toSeconds(long duration, TimeUnit timeUnit)
//package com.java2s; //License from project: Apache License import java.util.concurrent.TimeUnit; public class Main { public static int toSeconds(long duration, TimeUnit timeUnit) { int seconds = (int) timeUnit.toSeconds(duration); long inverseDuration = timeUnit.convert(seconds, TimeUnit.SECONDS); if (duration > inverseDuration) { //Round up. seconds++;//w ww . j ava2 s.c o m } return seconds; } }