Advertisement
Advertisement


HTML Display Current date


Question

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.... )

2019/11/07
1
16
11/7/2019 2:31:38 PM

Accepted 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>

2015/09/12
31
9/12/2015 3:55:08 PM


I prefer to use

<input type='date' id='hasta' value='<?php echo date('Y-m-d');?>'>

that works well

2017/01/04

This helped me:

<p>Date/Time: <span id="datetime"></span></p><script>var dt = new Date();
document.getElementById("datetime").innerHTML=dt.toLocaleString();</script>    
2019/11/07

var currentDate  = new Date(),
    currentDay   = currentDate.getDate() < 10 
                 ? '0' + currentDate.getDate() 
                 : currentDate.getDate(),
    currentMonth = currentDate.getMonth() < 9 
                 ? '0' + (currentDate.getMonth() + 1) 
                 : (currentDate.getMonth() + 1);

document.getElementById("date").innerHTML = currentDay + '/' + currentMonth + '/' +  currentDate.getFullYear();

You can read more about Date object

2015/09/12

  <script >
window.onload = setInterval(clock,1000);
function clock()
{
    var d = new Date();
    var date = d.getDate();
    var year = d.getFullYear();
    var month = d.getMonth();
    var monthArr = ["January", "February","March", "April", "May", "June", "July", "August", "September", "October", "November","December"];
    month = monthArr[month];
    document.getElementById("date").innerHTML=date+" "+month+", "+year;
}

2018/10/30