Users Pricing

articles

home / developersection / articles / entering current date in existing html control by using java script

Entering current date in existing html control by using java script

Anonymous User 8397 13 Mar 2011 Updated 04 Mar 2020

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>
Output of the following code snippet is as follows

Entering current date in existing html control by using java script


I am a content writter !


1 Comments