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="">
    <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(':');
<body onload="getdates()">
    <form id="form1">
        <h2>Javascript set date format in dd mm yyyy hh mm ss</h2>
            <b>Current Date:</b>
            <label id="lblCurrentDate" />
            <b>Date with dd mm yyyy format:</b>
            <label id="lblPreviousDate" />
            <b>Date with dd mm yyyy hh:mm:ss Format:</b>
            <label id="lbldateformat" />


Output - set date format

Demo Code

Download Demo