Java - Write code to convert milli seconds To String

Requirements

Write code to convert milli seconds To String

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        long ms = 12312342;
        System.out.println(millisToString(ms));
    }//from   w w w .ja  v a 2 s.c om

    public static String millisToString(long ms) {
        int days = (int) (ms / (1000 * 60 * 60 * 24)) % 7;
        int hours = (int) (ms / (1000 * 60 * 60)) % 24;
        int mins = (int) (ms / (1000 * 60)) % 60;
        int secs = (int) (ms / 1000) % 60;
        if (days > 0) {
            return String.format("%s days, %sh %sm %ss", days, hours, mins,
                    secs);
        } else if (hours > 0) {
            return String.format("%sh %sm %ss", hours, mins, secs);
        } else {
            return String.format("%sm %ss", mins, secs);
        }
    }
}