convert ‘1’ to ‘0001’ in JavaScript [duplicate]

Possible Duplicate:
Is there a JavaScript function that can pad a string to get to a determined length?

How can I convert convert ‘1’ to ‘0001’ in JavaScript without using any 3rd party libraries. I have done this in php using spritf: $time = sprintf('%04.0f',$time_arr[$i]);

4 Answers
4

Leave a Comment