2 Example(s) of JavaScript Date object


Description :

Example of JavaScript date function: Date() will print the complete date in innerHTML of paragraph tag. See the code snippet:


JavaScript Date object Example - 1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
    
</head>
<body>
<p id="sample"></p>
<script>
    document.getElementById("sample").innerHTML = Date();
</script>
</body>
</html>

Output

Description :

In this example, We will set the date using new Date("December 13, 2015 11:13:00") function. See the code snippet:


JavaScript Date object Example - 2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to LearnKode - A code learning platform</title>
    
</head>
<body>
<p id="sample"></p>
<script>
    var date = new Date("December 13, 2015 11:13:00");
document.getElementById("sample").innerHTML = date;
</script>
</body>
</html>

Output