Date Format in JavaScript

Introduction 

This article explains how to use JavaScript to set date format in dd/mm/yyyy hh:mm:ss

Script

<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>

HTML 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">
<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>
Ashwani
Ashwani

This is a short biography of the post author. Maecenas nec odio et ante tincidunt tempus donec vitae sapien ut libero venenatis faucibus nullam quis ante maecenas nec odio et ante tincidunt tempus donec.

No comments:

Post a Comment