×

Index

JavaScript Tutorial

JavaScript Examples

CSS Tutorial

CSS Examples

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

JavaScript Examples »



Related Examples



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.