Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Display Current date

Tags:

html

date

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

like image 784
Miqro Avatar asked Sep 12 '15 14:09

Miqro


People also ask

How do I display the current date and time in HTML?

Current Date and Time is stored inside javascript variable. Then using TextContent property the content of HTML span element is set with current and time. Unique ID is given to span tag so that we can use it on getElementById() method to dispaly the current date and time.

How display current date in textbox HTML?

<input type="text" name="frmDateReg" required id="frmDate" value=""> function getDate(){ var todaydate = new Date(); var day = todaydate. getDate(); var month = todaydate.

How do you code a date in HTML?

dd-mm-yyyy. mm-dd-yyyy.


2 Answers

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>
like image 171
Lance Avatar answered Sep 18 '22 14:09

Lance


Use Date::toLocaleDateString.

new Date().toLocaleDateString() = "9/13/2015" 

You don't need to set innerHTML, just by writing

<p> <script> document.write(new Date().toLocaleDateString()); </script> </p> 

will work.

supportness

P.S.

new Date().toDateString() = "Sun Sep 13 2015" 
like image 21
maowtm Avatar answered Sep 18 '22 14:09

maowtm