Answers for "javascript display time with leading zeros"

8

javascript print int with leading zeros

function padLeadingZeros(num, size) {
    var s = num+"";
    while (s.length < size) s = "0" + s;
    return s;
}
padLeadingZeros(57, 3);// "057"
padLeadingZeros(57, 4); //"0057"
Posted by: Guest on August-02-2019
0

Javascript add leading zeroes to date

var MyDate = new Date();
var MyDateString;

MyDate.setDate(MyDate.getDate() + 20);

MyDateString = ('0' + MyDate.getDate()).slice(-2) + '/'
             + ('0' + (MyDate.getMonth()+1)).slice(-2) + '/'
             + MyDate.getFullYear();
Posted by: Guest on January-07-2021
0

add leading zeros javascript

function pad(num, size) {
    num = num.toString();
    while (num.length < size) num = "0" + num;
    return num;
}
Posted by: Guest on April-02-2022

Code answers related to "javascript display time with leading zeros"

Code answers related to "Javascript"

Browse Popular Code Answers by Language