Introduction:
Here I will explain how to use JavaScript to set date format in dd/mm/yyyy hh:mm:ss with example or JavaScript change or set date format in dd/mm/yyyy hh:mm:ss with example. By using new Date() properties we can change date format to dd/mm/yyyy hh:mm:ss in JavaScript.
Description:
In previous articles I explained JavaScript replace special characters in string, jQuery create modal popup windows with example, jQuery remove whitespaces from string with regex, jQuery load more records on button click in repeater, jQuery fixed header on scroll with example, jQuery show asp.net exception message in ajax calls and many articles relating to css, AngularJS, jQuery, JavaScript and asp.net. Now I will explain how to change date format to dd/mm/yyyy hh:mm:ss in JavaScript with example.
In previous articles I explained JavaScript replace special characters in string, jQuery create modal popup windows with example, jQuery remove whitespaces from string with regex, jQuery load more records on button click in repeater, jQuery fixed header on scroll with example, jQuery show asp.net exception message in ajax calls and many articles relating to css, AngularJS, jQuery, JavaScript and asp.net. Now I will explain how to change date format to dd/mm/yyyy hh:mm:ss in JavaScript with example.
To change date format to dd/mm/yyyy hh:mm:ss
in JavaScript
we need to write the code like as shown below
<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>
|
If
you want to check it in complete example you need to write the code like as
shown below
<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>
|
Live
Demo
For live demo check below dates format
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.