Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Convert milliseconds into HH:mm:ss

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.
Labels (3)
3 Replies
Anonymous
Not applicable
Author

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.
Anonymous
Not applicable
Author

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 ?
gorotman
Creator II
Creator II

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? )