I'm trying to convert milliseconds to a formatted time string using the following:
function getTimeString(timeMs) {
return Qt.formatTime(new Date(timeMs), "h:mm:ss");
}
The problem is, when I give it 1 hour worth of time, instead of displaying 1:00:00
it displays 20:00:00
. Two hours similarly displays 21:00:00
. This is because of the timezone offset built into the Date object. There are some functions to remove the timezone offset that sound promising, but fall short, such as:
- Date.getUTCDate() which turns the QML Date object into a javascript Date object that can no longer be passed into Qt.formatTime(), and javascript seems to have no suitable alternative time formatting.
- Date.toUTCString() which doesn't take a format, so I would need some string manipulation to cut the unwanted parts out.
I could always just use repeated divisions and manually build the string from that, but what I have is fairly short and clear, and I'd like to keep it that way if possible.