Hi everyone,
I'd like to convert milliseconds ("duration" field from tStatCatcher) into a more readable format like HH:mm:ss (Date format or String).
Is there a Java method to do that easily ? Or do I have to do that with basic math formulas ?
TimeUnit does not seem to work... I tried to import java.util.concurrent.TimeUnit but Talend does not recognize it.
Thanks in advance for your help.
is this what you're looking for?
you can then format it as you wish.
Date(long date)
Allocates a
Date
object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
Thanks for your reply.
But could you please be more specific ?
I tried to put "new Date(row3.duration)" with type : Date, pattern : "HH:mm:ss" at the output of tMap and the result is (tLogRow) : 01:00:00 (which is one hour but my job takes only 400 milliseconds so I should have 00:00:00, right ?)
What am I missing ?
May be this helps you:
int millis=1000000000;
String ris=String.format("%02d:%02d:%02d",
java.util.concurrent.TimeUnit.MILLISECONDS.toHours(millis),
java.util.concurrent.TimeUnit.MILLISECONDS.toMinutes(millis) -
java.util.concurrent.TimeUnit.HOURS.toMinutes(java.util.concurrent.TimeUnit.MILLISECONDS.toHours(millis)), // The change is in this line
java.util.concurrent.TimeUnit.MILLISECONDS.toSeconds(millis) -
java.util.concurrent.TimeUnit.MINUTES.toSeconds(java.util.concurrent.TimeUnit.MILLISECONDS.toMinutes(millis)));
(look at
How to convert milliseconds to “hh:mm:ss” format? )