+6 votes
in Programming by (270 points)
i want a button and onClick  on that button current date and time in java script should populate .

in ui only button should show time and date should come after click.

Thanks for answer!

1 Answer

+3 votes
by (1.9k points)
edited by
Best answer

Hello navneet!

you can use java script like this 

<p id="display"></p>
<button type="button" onclick="myFunction()">Click me to get time</button>
function myFunction()
document.getElementById("display").innerHTML = Date();
here <p> is the place where the date and time will be shown.
in <p> output will come.
by (270 points)
thanks its working.
by Expert (5.1k points)
function ShowLocalDate()
var dNow = new Date();
var localdate= (dNow.getMonth()+1) + '/' + dNow.getDate() + '/' + dNow.getFullYear() + ' ' + dNow.getHours() + ':' + dNow.getMinutes();
<label id="currentDate"></p>
<button type="button" onclick="ShowLocalDate()">Show Local DateTime</button>

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated