I have input, 34600 milliseconds I would like to output this in the format 00:00:34 (HH:MM:SS).
What classes should I look at JDK / Joda-time for this? I need this to be efficient, preferably thread safe to avoid object creations on each parsing.
Thank you.
— EDIT —
Using this code produces time zone sensitive results, how can I make sure the formating is “natural”, i.e. uses absolute values.
import java.util.Locale;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
public class Test {
public static void main(String[] args) {
DateTimeFormatter fmt = DateTimeFormat.forPattern("kk:mm:ss").withLocale(new Locale("UTC"));
System.out.println(fmt.print(34600));
}
}
Results in 02:00:34 – The +2h is because my time zone is GMT+2. While the expected output is 00:00:34.
For a Joda solution, give this a try (given your updated question):
Outputs:
Regarding your preference for thread safety:
(from PeriodFormatterBuilder documentation)