hey

I'm trying to write a method that converts milliseconds to hours, minutes, and seconds using the following header:

public static String convertMillis(long millis)

My method needs to return a string as hours:minutes:seconds.

For example, convertMillis(5500) returns a string 0:0:5.

this is what i have so far, can someone please help me.

import java.util.*;
class Millis
{
    public static void main(String[] args) 
    {
    }

    public static String convertMillis(long millis) {

        double hours;
        double minutes;
        double seconds;
        int milliseconds = 0;
        int currentSeconds = 0;
        int totalSeconds = 0;
        int totalMinutes = 0;
        int totalHours = 0;

System.out.print("convertMillis:");
milliseconds = input.nextInt();

        seconds = milliseconds/1000;
        hours = seconds/(60*60);
        minutes = seconds % ((60*60));

    System.out.println("your conversion equals" hours + ":" + minutes + ":" + seconds);
return null;
}

Hope this solves your problem.

public static void convertMillis(int Millis){
        String convert = String.format("You have %d hour(s), %d minute(s), and %d second(s)",
                Millis/(1000*60*60), (Millis%(1000*60*60))/(1000*60), ((Millis%(1000*60*60))%(1000*60))/1000);
        System.out.println(convert);
    }

thanks, where would i put that

Figure it out. I noticed you have a tendency to not mark threads solved or to follow up on your old threads. Anyway, zetlin just gave you the exact method you need from the looks of things. Now you want him to edit it into your code for you?

Actually he pm me with the same question and I was nice enough to show him how to run it using just the class name.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.