dimanche 17 novembre 2019

JavaScript - if statment inside function

I've got problem with this function. I want it to add '0' to date if it is below ten.

var date = new Date();
var day = date.getDate();
var month = date.getMonth()+1;
var year = date.getFullYear();
var hour = date.getHours();
var minutes = date.getMinutes();
function check(x){
if (x < 10){
    x = '0' + x
}};
check(hour);
console.log(hour);

But when I check console.log(hour); it still returns previous value. What is the case?

Aucun commentaire:

Enregistrer un commentaire