How to create a custom date and time format in JavaScript ?

How can I create a custom date and time format in JavaScript ?
0
give a positive ratinggive a negative rating
13 Dec 2022 at 05:38 PM
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
give a positive ratinggive a negative rating
14 Dec 2022 at 11:57 AM
Tim
Share on FacebookShare on TwitterShare on LinkedInSend email
x
x
2024 AnswerTabsTermsContact us