How do I get the current date in JavaScript?

How do I get current date in JavaScript?

Text Copied From stackoverflow.com
on : Wed, Oct 07, 2009 Views : 1715640

Accepted Answer

Use new Date() to generate a new Date object containing the current date and time.

var today = new Date();
 var dd = today.getDate();
 var mm = today.getMonth()+1;
 
//January is 0! var yyyy = today.getFullYear();
  if(dd<10) 
{

  dd = '0'+dd 
}   if(mm<10) 
{

  mm = '0'+mm 
}   today = mm + '/' + dd + '/' + yyyy;
 document.write(today);

This will give you today's date in the format of mm/dd/yyyy.

Simply change today = mm +'/'+ dd +'/'+ yyyy;
to whatever format you wish.

Text Copied From stackoverflow.com
on : Tue, Feb 08, 2011

Ask Question

If you want to ask question you must LogIn or SignUp
Login SignUp

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp