Javascript set date format

The article shows how to change date format to dd/mm/yyyy hh:mm:ss in JavaScript. To set date format add the below code in aspx page.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Javascript set date format in dd mm yyyy hh mm ss</title>
    <script type="text/javascript">
        function getdates() {
            var today = new Date()
            document.getElementById('lblCurrentDate').innerHTML = today;
            document.getElementById('lblPreviousDate').innerHTML = [today.getDate(), today.getMonth() + 1, today.getFullYear()].join('/');
            document.getElementById('lbldateformat').innerHTML = [today.getDate(), today.getMonth() + 1, today.getFullYear()].join('/') + ' ' + [today.getHours(), today.getMinutes(), today.getSeconds()].join(':');
        }
    </script>
</head>
<body onload="getdates()">
    <form id="form1">
        <h2>Javascript set date format in dd mm yyyy hh mm ss</h2>
        <div>
            <b>Current Date:</b>
            <label id="lblCurrentDate" />
        </div>
        <div>
            <b>Date with dd mm yyyy format:</b>
            <label id="lblPreviousDate" />
        </div>
        <div>
            <b>Date with dd mm yyyy hh:mm:ss Format:</b>
            <label id="lbldateformat" />
        </div>
    </form>
</body>
</html>

 Output

Output - set date format

Demo Code

Download Demo