How to define and manipulate Date variable in JavaScript?
<p>I need to use the <code>Date</code> object for three different purposes, can I do this as follows?</p>

<p>I am very new to JavaScript, so I am not sure if the following define is OK for all the browsers.</p>

<pre><code>Date.prototype.yyyymmdd = function() 
{
  var yyyy = this.getFullYear().toString();    
  var mm = (this.getMonth()+1).toString(); 
  var dd  = this.getDate().toString();    
  return yyyy+"-" + (mm[1]?mm:"0"+mm[0])+"-" + (dd[1]?dd:"0"+dd[0]); 

}; 

Date.prototype.mmddyyyy = function() 
{
  var yyyy = this.getFullYear().toString();    
  var mm = (this.getMonth()+1).toString(); 
  var dd  = this.getDate().toString();    

  return (mm[1]?mm:"0"+mm[0])+"-" + (dd[1]?dd:"0"+dd[0])+"-" + yyyy; 
}; 

Date.prototype.mmdd = function() 
{
   var yyyy = this.getFullYear().toString();    
   var mm = (this.getMonth()+1).toString(); 
   var dd  = this.getDate().toString();    
   return (mm[1]?mm:mm[0])+"/" + (dd[1]?dd:dd[0]);
};


var d0 = new Date();
console.log(d0.mmddyyyy);

var d1 = new Date();
console.log(d1.yyyymmdd);

var d2 = new Date();
console.log(d2.mmdd);
</code></pre>
