I have a value in milliseconds that I would like to display as hours:minutes:seconds in a datafield.
Is there some built in functionality to do that conversion?
The millisecond value may be both negative (behind) or positive (ahead).
I have a value in milliseconds that I would like to display as hours:minutes:seconds in a datafield.
Is there some built in functionality to do that conversion?
The millisecond value may be both negative (behind) or positive (ahead).
using Toybox.Time as Time;
var curr_milli = Time.now().value() + milliseconds;
var tinfo = Time.Gregorian.info(new Time.Moment(curr_milli), Time.FORMAT_SHORT);
var text = tinfo.hour.format("%02d") + ":" + tinfo.min.format("%02d") + ":" + tinfo.sec.format("%02d");
function toHMS(secs) {
var hr = secs/3600;
var min = (secs-(hr*3600))/60;
var sec = secs%60;
return hr.format("%02d")+":"+min.format("%02d")+":"+sec.format("%02d");
}
//var msValue = ......
var sign = "";
if (msValue < 0) {
sign = "-";
msValue *= -1;
}
var hours = msValue / 1000 / 60 / 60;
var mins = (msValue / 1000 / 60) % 60;
var secs = (msValue / 1000) % 60;
var timeStr = Lang.format("$1$$2$:$3$:$4$", [sign, hours.format("%01d"), mins.format("%02d"), secs.format("%02d")]);