There is an array and date:


var m = [0,0,0]; var t = new Date(); 

 alert(t.getDate()+t.getHours()+t.getMinutes()); // показывает, например, 272157; 

How to correctly put this 272157 as a number in the last element of the array?

 m[2] = t.getDate()+t.getHours()+t.getMinutes(); // складывает и вносит число 105; 

    1 answer 1

    Well, if it is very simple, you can do so :)

     m[2] = '' + t.getDate()+t.getHours()+t.getMinutes(); 
    • Indeed, it works, thank you very much. - Alex
    • one
      @Alex, there is no leading zero. - Qwertiy
    • one
      If you need a leading zero, the easiest way to do this is m[2] = '' + ((t.getDate() < 10) ? '0' : '') + t.getDate() + ((t.getHours() < 10) ? '0' : '') + t.getHours() + ((t.getMinutes() < 10) ? '0' : '') + t.getMinutes() - Nastya
    • Thank you, very valuable note and help. - Alex