Introduction
This article explains how to use JavaScript to set date format in dd/mm/yyyy hh:mm:ssScript
<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>
<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>
No comments:
Post a Comment