Reputation: 2615
I need a String format of a date like this " 3.456" (3 seconds and 456 milliseconds) but the milliseconds its not working
gameStart is filled when the game begin with System.currentTimeMillis();
loopStart = System.currentTimeMillis();
long prueba = loopStart-gameStart;
puntuacionString = (String) DateFormat.format("mm.ss.SSS", prueba);
It return something like "00.01.SSS" on the first second, what I m doing wrong?
Upvotes: 0
Views: 182
Reputation: 6909
DateFormat.format does not recognise the .SSS formatting option. You have to use use the SimpleDateFormat object, as that supports formatting data the way you want it. Try instantiating it and passing in your time to format, like so:
loopStart = System.currentTimeMillis();
long prueba = loopStart-gameStart;
SimpleDateFormat date = new SimpleDateFormat("mm.ss.SSS");
puntuacionString = date.format(prueba);
Upvotes: 2
Reputation: 14408
Try same format with SimpleDateFormat
as
SimpleDateFormat formatter = new SimpleDateFormat("mm.ss.SSS");
loopStart = System.currentTimeMillis();
long prueba = loopStart-gameStart;
puntuacionString = formatter.format(new Date(prueba));
Upvotes: 2