# Convert milliseconds to hours, minutes, and seconds

Page 1 of 1

## 6 Replies - 19618 Views - Last Post: 03 May 2012 - 08:18 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=277985&amp;s=abb941d140b2bf6c89ed70592fc35abe&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Jagst3r15

Reputation: 1
• Posts: 77
• Joined: 21-December 10

# Convert milliseconds to hours, minutes, and seconds

Posted 03 May 2012 - 08:01 PM

So this is embarrassing, but I needed to re-do a lab since my teacher lost it and I deleted the file! I would appreciate any guidance. I think the title is self explanatory , so I am pretty much stuck with some of my math and am getting an error - it says it cannot find symbol 'convert' on line 13?

Here is my code:

```import java.util.Scanner;

public class convertMillis {
public static void main(String[] args) {

long seconds, minutes, hours;

Scanner input = new Scanner(System.in);

long milliseconds = 0;
System.out.print("Enter an amount in miliseconds:");
milliseconds = input.nextLong();
String time = convert(milliseconds);
System.out.print(time);

}
public static String convertMillis(long milliseconds){
long seconds, minutes, hours;
seconds = milliseconds / 1000;
hours = seconds / 3600;
seconds = seconds % 3600;
seconds = seconds / 60;
minutes = minutes % 60;

return("Your conversion is: " + seconds + ":" + minutes + ":" + hours);
}
}
```

Is This A Good Question/Topic? 0

## Replies To: Convert milliseconds to hours, minutes, and seconds

### #2 DimitriV

• vexing conundrum

Reputation: 587
• Posts: 2,746
• Joined: 24-July 11

## Re: Convert milliseconds to hours, minutes, and seconds

Posted 03 May 2012 - 08:06 PM

There is a procedure called convertMillis. There isn't a procedure called convert. Try replacing the call to convert with convertMillis

### #3 Jagst3r15

Reputation: 1
• Posts: 77
• Joined: 21-December 10

## Re: Convert milliseconds to hours, minutes, and seconds

Posted 03 May 2012 - 08:11 PM

Thanks a bunch Dimitri . I am now getting an error: variable minutes might not have been initialized. I am pretty sure i declared minutes though, right?

### #4 DimitriV

• vexing conundrum

Reputation: 587
• Posts: 2,746
• Joined: 24-July 11

## Re: Convert milliseconds to hours, minutes, and seconds

Posted 03 May 2012 - 08:14 PM

You have never given minutes a value in that code.
```long seconds, minutes, hours;
seconds = milliseconds / 1000;
hours = seconds / 3600;
seconds = seconds % 3600;
seconds = seconds / 60;
minutes = minutes % 60;

```

Do you see minutes with a value? You try to modulo an empty long. I don't think that is right.

### #5 Jagst3r15

Reputation: 1
• Posts: 77
• Joined: 21-December 10

## Re: Convert milliseconds to hours, minutes, and seconds

Posted 03 May 2012 - 08:17 PM

This better?

```public static String convertMillis(long milliseconds){
long seconds, minutes, hours;
seconds = milliseconds / 1000;
minutes = seconds / 60;
seconds = seconds % 60;
hours = minutes / 60;
minutes = minutes % 60;

return("Your conversion is: " + hours + ":" + minutes + ":" + seconds);
}

```

### #6 DimitriV

• vexing conundrum

Reputation: 587
• Posts: 2,746
• Joined: 24-July 11

## Re: Convert milliseconds to hours, minutes, and seconds

Posted 03 May 2012 - 08:18 PM

Is it working for you?

### #7 Jagst3r15

Reputation: 1
• Posts: 77
• Joined: 21-December 10

## Re: Convert milliseconds to hours, minutes, and seconds

Posted 03 May 2012 - 08:18 PM

Yea it worked don't know why I asked if it's better hehe . Thanks for the help.