class DateUtils {

	public static String formatDuration(long millis) {
		long days = 0;
		int hours = 0;
		int minutes = 0;
		int seconds = 0;
		if (millis >= MS_PER_DAY) {
			days = millis / MS_PER_DAY;
			millis = millis % MS_PER_DAY;
		}
		if (millis >= MS_PER_HOUR) {
			hours = (int) (millis / MS_PER_HOUR);// this cast is safe
			millis = millis % MS_PER_HOUR;
		}
		if (millis >= MS_PER_MIN) {
			minutes = (int) (millis / MS_PER_MIN);
			millis = millis % MS_PER_MIN;
		}
		if (millis >= MS_PER_SEC) {
			seconds = (int) (millis / MS_PER_SEC);
			millis = millis % MS_PER_SEC;
		}
		StringBuilder sb = new StringBuilder();
		if (days > 0) {
			sb.append(Long.toString(days)).append(" days, ");
		}
		if (sb.length() > 0 || hours > 0) {
			sb.append(Integer.toString(hours)).append(" hours, ");
		}
		if (sb.length() > 0 || minutes > 0) {
			sb.append(Integer.toString(minutes)).append(" mins, ");
		}
		sb.append(Integer.toString(seconds)).append(" secs");

		return sb.toString();
	}

}