Home » JavaScript

Get current Date in Date / Month / Year format in JavaScript

JavaScript getting the current Date in DD/MM/YY format: Here, we are going to learn how to get the current date in JavaScript in Date / Month / Year format?
Submitted by IncludeHelp, on March 04, 2019

Getting current date in JavaScript

To get the current date in JavaScript, we need to use three library functions of Date class,

  1. Date getDate() Method – It returns current date (day of the month)
  2. Date getMonth() Method – It returns current month of the year
  3. Date getFullYear() Method – It returns current year in 4 digits format

Note: To call these functions, we need to create an object to the Date class using Date class constructor.

Examples:

    Date class constructor:
    var dt = new Date();

    Function calls:
    dt.getDate();
    dt.getMonth()+1;
    dt.getFullYear();
    
    Output:
    4
    3
    2019

JavaScript code to get the current date in Date / Month / Year format

<html>
<head><title>JavaScipt Example</title></head>

<body>
<script>
	var dt = new Date(); //Date constructor 
	var dd = dt.getDate();
	var mm = dt.getMonth()+1;
	var yy = dt.getFullYear();
	//printing date
	document.write("Current date is= " + dd + "/" + mm + "/" + yy + "<br>");
</script>
</body>
</html>

Output

Current date is= 4/3/2019





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.