Converting time

JavaScript performance comparison

Test case created by Axel Michel

Info

Getting all digits from a hour minute string

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
by Math.floor
d = new Date();
h = d.getHours();
m = d.getMinutes();
var h1 = Math.floor(h / 10);
var h2 = h % 10;
var h3 = Math.floor(m / 10);
var h4 = m % 10;
 
pending…
by toString
var d = new Date(),
    h = ((h = d.getHours()) < 10 ? '0' + h : h).toString(),
    m = ((m = d.getMinutes()) < 10 ? '0' + m : m).toString();
 
pending…
by toString/split
var d = new Date(),
    h = ((h = d.getHours()) < 10 ? '0' + h : h).toString().split(''),
    m = ((m = d.getMinutes()) < 10 ? '0' + m : m).toString().split('');
 
pending…
by parseInt
d = new Date();
h = d.getHours();
m = d.getMinutes();
var h1 = parseInt((h / 10),10);
var h2 = h % 10;
var h3 = parseInt((m / 10),10);
var h4 = m % 10;
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment