current date in javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kiranbabu
    New Member
    • Jun 2009
    • 10

    #1

    current date in javascript

    pls any one help me

    I want current date in dd/mm/yyyy format in javascript
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You can get the current date with:
    Code:
    var today = new Date();
    Then use the get*** methods to get the day, month and year. Note that getMonth() is 0-based, i.e. 0=January, and use getFullYear() for the year, not getYear().

    Comment

    • rnd me
      Recognized Expert Contributor
      • Jun 2007
      • 427

      #3
      Code:
      Date.prototype.toShort = function () {
          function f(n) {
              return n < 10 ? "0" + n : n;
          }
          return f(this.getDate() ) + "/" + f(this.getMonth() + 1) + "/" +  this.getFullYear()   ;
      };
      
      alert((new Date).toShort());//==="25/07/2009"

      Comment

      Working...