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);
convertMilliseconds(3661000);
convertMilliseconds(3661000, “hh:mm:ss”);
convertMilliseconds(3661000, “mm:hh:ss”);
convertMilliseconds(3661000, “ss:mm:hh”);
convertMilliseconds(3661000, “mm:ss”);
convertMilliseconds(3661000, “ss”);
convertMilliseconds(3661000, “h:m:s”);
convertMilliseconds(3661000, “m:s”);
convertMilliseconds(3661000, “s”);

Gist

"Convert Milliseconds into digital time [ 00:00 ]" was published on March 11th, 2011 and is listed in My Work.

Follow comments via the RSS Feed | Leave a comment | Trackback URL