In this tutorial learn how to format JavaScript date.
EXAMPLE 1
EXAMPLE 2
The output of above example : 23-Sep-2019
EXAMPLE 1
The above example output: 23-9-2019 22:47<html><button onclick="myFunction()">Click me</button><script>function myFunction() {var d = new Date();var datestring = d.getDate() + "-" + (d.getMonth()+1) + "-" + d.getFullYear() + " " +d.getHours() + ":" + d.getMinutes();alert(datestring);}</script></html>
EXAMPLE 2
<html>
<button onclick="myFunction()">
Click me
</button>
<script>
function myFunction() {
var D = new Date();
var now = new Date()
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
var formattedDate = now.getDate() + "-" + months[now.getMonth()] + "-" + now.getFullYear()
alert(formattedDate)
}
</script>
</html>
The output of above example : 23-Sep-2019
No comments:
Post a Comment