JavaScript Date – Display Current Date in dd/mm/yyyy Format

datejavascript

I am using website builder called 'clickfunnels', and they don't support feature that would allow me to display current date. But, I can add custom HTML to it.

I was wondering if anyone knows how to show on website current date in format: dd/mm/yyyy

Currently I've tried this:

<p id="date"></p>
<script>
document.getElementById("date").innerHTML = Date();
</script>

And this works, but it displays date likes this:

Sat Sep 12 2015 16:40:10 GMT+0200 (Timezone…. )

Best Answer

Here's one way. You have to get the individual components from the date object (day, month & year) and then build and format the string however you wish.

n =  new Date();
y = n.getFullYear();
m = n.getMonth() + 1;
d = n.getDate();
document.getElementById("date").innerHTML = m + "/" + d + "/" + y;
<p id="date"></p>