title: Javascript get date in format
body: <p>I want to get today's date in the format of mm-dd-yyyy</p>
  
  <p>I am using <code>var currentDate = new Date();
  document.write(currentDate);
  </code></p>
  
  <p>I can't figure out how to format it. </p>
  
  <p>I saw the examples <code>var currentTime = new Date(YY, mm, dd);</code> and <code>currentTime.format("mm/dd/YY");</code></p>
  
  <p>Both of which don't work</p>
  
  <p>I finally got a properly formatted date using </p>
  
  <pre><code>var today = new Date();
  var dd = today.getDate();
  var mm = today.getMonth()+1;//January is 0!`
  
  var yyyy = today.getFullYear();
  if(dd&lt;10){dd='0'+dd}
  if(mm&lt;10){mm='0'+mm}
  var today = mm+'/'+dd+'/'+yyyy;
  document.write(today);'`
  </code></pre>
  
  <p>This seems very complex for such a simple task.</p>
  
  <p>Is there a better way to get today's date in <code>dd/mm/yyyy</code>?</p>