Connecting Tech Pros Worldwide Help | Site Map

current date in javascript

Newbie
 
Join Date: Jun 2009
Posts: 9
#1: Jul 24 '09
pls any one help me

I want current date in dd/mm/yyyy format in javascript
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#2: Jul 24 '09

re: current date in javascript


You can get the current date with:
Expand|Select|Wrap|Line Numbers
  1. 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().
rnd me's Avatar
Expert
 
Join Date: Jun 2007
Location: Urbana IL
Posts: 411
#3: Jul 25 '09

re: current date in javascript


Expand|Select|Wrap|Line Numbers
  1.  
  2. Date.prototype.toShort = function () {
  3.     function f(n) {
  4.         return n < 10 ? "0" + n : n;
  5.     }
  6.     return f(this.getDate() ) + "/" + f(this.getMonth() + 1) + "/" +  this.getFullYear()   ;
  7. };
  8.  
  9. alert((new Date).toShort());//==="25/07/2009"
  10.  
  11.  
Reply