Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Formats the amount of time in a friendly way.
- *
- * @param millis Amount of time in milliseconds.
- * @param nicly When the amount of time is less than 1 minute, the message will be cool.
- * @return Friendly description of the amount of time.
- */
- public static String friendlyAmountTime(long millis, boolean nicly)
- {
- long hours = TimeUnit.MILLISECONDS.toHours(millis);
- long minutes = TimeUnit.MILLISECONDS.toMinutes(millis);
- long seconds = TimeUnit.MILLISECONDS.toSeconds(millis);
- StringBuilder sb = new StringBuilder();
- if (nicly)
- {
- sb.append("Really fast!");
- }
- else
- {
- sb.append("< 1 second");
- }
- if (millis > 999)
- {
- sb.delete(0, sb.length());
- if (hours > 0)
- {
- sb.append(hours);
- sb.append(" hour");
- if (hours > 1)
- {
- sb.append("s");
- }
- }
- if (minutes > 0)
- {
- sb.append(" ");
- sb.append(minutes);
- sb.append(" minute");
- if (minutes > 1)
- {
- sb.append("s");
- }
- }
- if (seconds > 0)
- {
- sb.append(" ");
- sb.append(seconds);
- sb.append(" second");
- if (seconds > 1)
- {
- sb.append("s");
- }
- }
- }
- return sb.toString().trim();
- }
Add Comment
Please, Sign In to add comment