title: How to add leading "0" to month/day of date string?
body: <p>so i wrote up a method that takes a number and subtracts the amount of months from the current date. </p>
  
  <p>I am trying to figure out how can i add a '0' in front of the months that are less that 10. Also, how can I add a '0' in front on the days that are less than ten as well. </p>
  
  <p>Currently, when it returns the object (2012-6-9). It returns 6 and 9 with no '0' in front of it, can someone show me how to do it? </p>
  
  <p>Here is my code</p>
  
  <pre><code>lastNmonths = function(n) {
      var date = new Date();
  
      if (n &lt;= 0)
          return [date.getFullYear(), date.getMonth() + 1 , date.getDate()].join('-');
      var years = Math.floor(n/12); 
  
  
     var months = n % 12;
  
  
      if (years &gt; 0)
          date.setFullYear(date.getFullYear() - years);
  
      if (months &gt; 0) {
          if (months &gt;= date.getMonth()) {
              date.setFullYear(date.getFullYear()-1 );
              months = 12 - months; 
              date.setMonth(date.getMonth() + months );
          } else {
              date.setMonth(date.getMonth() - months);
          }
      }
  
  }
  
      return [date.getFullYear(), date.getMonth() + 1, date.getDate()].join('-');
  };
  </code></pre>