Here you can find the source of timeToString(int time)
Parameter | Description |
---|---|
time | Time in seconds |
public static String timeToString(int time)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . jav a2s .c o m * Converts seconds to a more friendly strings. Will convert up to days. * * @param time * Time in seconds * @return A friendly string, which converts the seconds into days, hours, * minutes, and seconds. */ public static String timeToString(int time) { String message = ""; if (time > 60) { int minutes = (int) Math.floor(time / 60), seconds = time - (minutes * 60); if (minutes > 60) { int hours = (int) Math.floor(minutes / 60); minutes -= (hours * 60); if (hours > 24) { int days = (int) Math.floor(hours / 24); message += days + " day"; if (days > 1) { message += "s"; } message += ", "; hours -= (days * 24); } message += hours + " hour"; if (hours > 1) { message += "s"; } message += ", "; } message += minutes + " minute"; if (minutes > 1) { message += "s"; } if (seconds > 0) { message += " and " + (seconds) + " seconds"; } } else { message += time + " seconds"; } return message; } }