How to create a custom date and time format in JavaScript ?
How can I create a custom date and time format in JavaScript ?
Hi,
To get a custom date format in Javascript, you use the solution below. First you get the current date or custom date into variable "d" and then you can create peferred date and time format. You can choose if you need to have a 24 hour or 12 hour format etc.
<script>
function getDate() {
var d = new Date();
var v = d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate()+' '+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds();
return v;
}
</script>
1 answer