tags:

views:

49

answers:

3

I want to display digits with leading 0s, for values of a single digit, specifically for displaying hours and minutes.

How do I do that in PHP?

+4  A: 
str_pad($number, 2, '0', STR_PAD_LEFT);
zerkms
Thanks Buddy....hats off
diEcho
is there any similar function in javascript??
diEcho
@I Like PHP - No built in function I know of. Just use the following:String.prototype.leftPad = function (l, c) { return (l < this.length) ? this: new Array(l - this.length + 1).join(c || '0') + this; }Example: var str = "123";alert(str.leftPad(5,"0")); // 00123
Aaron W.
@Aaron Thanks Dear
diEcho
A: 

Use $val = 1 ;

print "0".$val ;
pavun_cool
How does that deal with `$minutes = 10`?
Dominic Rodger
A: 

Or take a look at the sprintf() function: http://www.php.net/manual/en/function.sprintf.php

Macmade