In this demonstration I will tell you that how to display date with different format and enter it in an existing html control like <p> (paragraph).
Write down following code snippet in notepad and save it with .html extension.
Code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function displayDate() {
var now = new Date();
var message = "For MM/DD/YYYY format <br />";
var mdyFormat = now.getMonth() + "/" + now.getDate() + "/" + now.getYear();
message = message + mdyFormat + "<br />";
message = message + "For DD/MM/YYYY format <br />";
mdyFormat = now.getDate() + "/" + now.getMonth() + "/" + now.getYear() + "<br />";
message = message + mdyFormat + "For YYYY/MM/DD format <br />";
mdyFormat = now.getYear() + "/" + now.getMonth() + "/" + now.getDate();
message = message + mdyFormat;
document.getElementById('datedemo').innerHTML = message;
}
</script>
</head>
<body>
<h1>Date Demonstration.</h1>
<p id="datedemo">
</p><br />
<input type="button" value="Display Date" onclick="displayDate()" />
</body>
</html>
Anonymous User
08-Apr-2019Thanks for the guidance.