How to get current date in javascript

How to get current date in javascript :

You get current date in javascript using the Date() function which returns the current date as per your timestamp.

Get current date in javascript

<html>
<head>
<title>Javascript Date Time Demo</title>
</head>
<body>
<div id="demoDate"></div>
</body>
<script>
var currDate = new Date();
document.getElementById("demoDate").innerHTML = currDate;
</script>
</html>

Try it »

Displaying Dates In Javascript :

Using .toUTCstring() It converts date in UTC String(a standard format to date display)

Display Date in UTC Standard In Javascript

<html>
<head>
<title>Javascript Date Time Demo</title>
</head>
<body>
<div id="demoDate"></div>
</body>
<script>
var currDate = new Date();
document.getElementById("demoDate").innerHTML = currDate.toUTCString();
</script>
</html>

Try it »

Using .toDatestring() It converts date in user friendly date format.

Display Date in DateString Standard In Javascript

<html>
<head>
<title>Javascript Date Time Demo</title>
</head>
<body>
<div id="demoDate"></div>
</body>
<script>
var currDate = new Date();
document.getElementById("demoDate").innerHTML = currDate.toDateString();
</script>
</html>

Try it »


Add Comment

📖 Read More


Advertisements