Answers for "add zero if single digit javascript"

3

js number add zero before

('0' + 11).slice(-2) // '11'
('0' + 4).slice(-2)  // '04'
Posted by: Guest on December-05-2020
1

add zero in front of numbers javascript

function checkTime(i) {
    if (i<10) {i = "0" + i};  // add zero in front of numbers < 10
    return i;
}
Posted by: Guest on September-03-2021
1

Adding "0" if clock have one digit

let str = "34"

str = str.padStart(4, "0") // results in "0034"
console.log(str)

For Clock Example : 

var now = new Date(); 
var year= now.getFullYear(); 
var month= (now.getMonth()+1).toString().padStart(2, "0");
var day= now.getDate().toString().padStart(2, "0");
var hour = now.getHours().toString().padStart(2, "0");
var minute = now.getMinutes().toString().padStart(2, "0");

document.getElementById("date").innerHTML =`${day}-${month}-${year}-${hour}:${minute}`;

<div id="date"></div>
Posted by: Guest on June-28-2020
0

add zero in front of numbers lower than 10 python

print(f"{x:02}") # where x is the integer
Posted by: Guest on June-22-2020

Code answers related to "add zero if single digit javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language