Is there a clean way of adding a 0 in front of the day or month when the day or month is less than 10:
var myDate = new Date(); var prettyDate =(myDate.getFu
The easiest way to do this is to prepend a zero and then use .slice(-2). With this function you always return the last 2 characters of a string.
zero
.slice(-2)
string
var month = 8;
var monthWithLeadingZeros = ('0' + month).slice(-2);
Checkout this example: http://codepen.io/Shven/pen/vLgQMQ?editors=101