-1

I'm doing a countdown timer, I got rid of int variable and made long. The following methods how I get hours, minutes and seconds.

public static long getHours(long totalSeconds) {
    return (long) Math.floor(totalSeconds / 3600000);
}

public static long getMinutes(long totalSeconds) {
    return (long) Math.floor((totalSeconds - 3600000 * getHours(totalSeconds)) / 60000);
}

public static long getSeconds(long totalSeconds) {
    return (long) Math.floor(totalSeconds - 3600000 * getHours(totalSeconds) - 60000 * getMinutes(totalSeconds));
}

public static long getMilliseconds(long totalSeconds) {
    return (long) Math.floor(getSeconds(totalSeconds) / 1000);
}

For ms I divided the second by 1000. Now I get time in such format 12:34:56.000. In place of milliseconds are always .000

What is wrong? How to get milliseconds?

P. Dm
  • 125
  • 12

2 Answers2

1

"Milli" comes from the Latin language. It means "a thousandth" of something.

Maybe that gives you a hint how you turn a second value into a milli second value.

GhostCat
  • 137,827
  • 25
  • 176
  • 248
0

Hope this will help you:

public static int getHours(int totalSeconds) {
    return  TimeUnit.SECONDS.toMillis(your seconds);
}
abarisone
  • 3,707
  • 11
  • 35
  • 54
MurugananthamS
  • 2,395
  • 4
  • 20
  • 49