-1

I'm trying to add milliseconds in my String, actually I'm using this:

time.update(String.format(textFormat, TimeUnit.MILLISECONDS.toMinutes(millis), TimeUnit.MILLISECONDS.toSeconds(millis), millis);

textFormat = "%02d:%02d:%02d";

The result I want is like this:

image of desired result

But I get this:

image of actual result

What should I do? Can I get this using maths?

1 Answers1

1

The last value should be reduced modulo 1000, since you want milliseconds past the last complete second.

millis % 1000

And then you'll want %03d, on account of there being 1000 milliseconds in a second.

If you really only want two digits, that's centiseconds, not milliseconds, so use

(millis % 1000) / 10