E
erictetz
My application is running an 'elapsed time' counter, which I would
like to display in HH:MM:SS format. My question is how best to do this
in Java. Note, I'm not using the latest version of Java which contains
printf (which makes this trivial).
I'm currently building the string by hand, but it's ugly. I tried
using SimpleDateFormat to do the work for me, but for reasons I don't
understand it adds 16 hours to the output. For example:
Date elapsedTime = Date(0); // 0 seconds elapsed, should be 00:00:00
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
System.out.println(dateFormat.format(elapsedTime));
This outputs 16:00:00. I have no clue how to get rid of the 16.
What am I doing wrong? Is there a cleaner approach for this?
Cheers,
Eric
like to display in HH:MM:SS format. My question is how best to do this
in Java. Note, I'm not using the latest version of Java which contains
printf (which makes this trivial).
I'm currently building the string by hand, but it's ugly. I tried
using SimpleDateFormat to do the work for me, but for reasons I don't
understand it adds 16 hours to the output. For example:
Date elapsedTime = Date(0); // 0 seconds elapsed, should be 00:00:00
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
System.out.println(dateFormat.format(elapsedTime));
This outputs 16:00:00. I have no clue how to get rid of the 16.
What am I doing wrong? Is there a cleaner approach for this?
Cheers,
Eric