Hey there! any question in your mind? Ask It Now!.

Popular Categories





onClick current date and time in java script

+6 votes
2,290 views
asked in Programming by navneet (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
answered by Eathen (1,930 points)
edited by Bhartesh
 
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>
 
<script>
function myFunction()
{
document.getElementById("display").innerHTML = Date();
}
</script>
here <p> is the place where the date and time will be shown.
in <p> output will come.
 
 
commented by navneet (270 points)
thanks its working.
commented by amit_pammu Expert (5,030 points)
<html>
<head>
<script>
function ShowLocalDate()
{
var dNow = new Date();
var localdate= (dNow.getMonth()+1) + '/' + dNow.getDate() + '/' + dNow.getFullYear() + ' ' + dNow.getHours() + ':' + dNow.getMinutes();
document.getElementById("currentDate").innerHTML=localdate;
}
 
</script>
</head>
<body>
 
<label id="currentDate"></p>
<button type="button" onclick="ShowLocalDate()">Show Local DateTime</button>
 
</body>
</html>

Related Questions

+2 votes
1 answer 191 views
0 votes
1 answer 9,925 views
+7 votes
1 answer 622 views
asked in Programming by neha (560 points)
+3 votes
1 answer 60 views
+5 votes
2 answers 1,217 views
+1 vote
1 answer 270 views
+1 vote
1 answer 160 views
asked in Programming by amit_pammu Expert (5,030 points)
+1 vote
2 answers 126 views
+6 votes
3 answers 7,059 views
+4 votes
5 answers 3,139 views

Not a Member yet?

Ask to Folks Login

My Account
452 Folks are online
1 members and 451 guest online
Your feedback is highly appreciated