Home » My Work » Convert Milliseconds into digital time [ 00:00 ]
Mar11
Convert Milliseconds into digital time [ 00:00 ]
0
JavaScript works with time in milliseconds, which is less than convenient when you want to present time back to your users. Here’s a little function that can help you convert milliseconds into a more human readable digital clock style string.
Properties
The function will return a object which contain the properties
var obj = convertMilliseconds(3661000);
obj.hours //–> 1 hour
obj.minuets //–> 1 min
obj.seconds //–> 1 sec
obj.clock //–> “01:01:01″
Usage
convertMilliseconds accepts two arguments
milliseconds: number of milliseconds to convert ex: 1000 type: number
pattern: formats the returned value of clock property ex: hh:mm:ss or ss:mm:h or ss:mm etc. type: string
A few more examples of convertMilliseconds(milliseconds, pattern);