My Service Call gives me a time display in seconds ex.(30042), i then map it to a label. Is there any java I can add to change it to a time format like this (08:20:42). I have tried some code from sources I googled but none would work.
My Service Call gives me a time display in seconds ex.(30042), i then map it to a label. Is there any java I can add to change it to a time format like this (08:20:42). I have tried some code from sources I googled but none would work.
Can you show us the code that you tried? You can also look if this library might help you: http://momentjs.com/
String.prototype.toHHMMSS = function () {
var sec_num = parseInt(this, 10); // don't forget the second parm
var hours = Math.floor(sec_num / 3600);
var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
var seconds = sec_num - (hours * 3600) - (minutes * 60);
Code: Select all
if (hours < 10) {hours = "0"+hours;}
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
var time = hours+':'+minutes+':'+seconds;
return time; }
Did you debug it line by line to make sure you get correct values..?