Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
want to show current time on the page and that should be changed without click on the refresh button of browser.for this i m using update panel and time is showing by me on the label but i want that it should be refresh itself and time should be changed itself...help me
Posted

try using this javascript

C#
function updateClock() {
    var now = new Date(), // current date
        months = ['January', 'February', '...']; // you get the idea
        time = now.getHours() + ':' + now.getMinutes(), // again, you get the idea

        // a cleaner whay than strin concatenation
        date = [now.getDate(),
                months[now.getMonth()],
                now.getFullYear()].join(' ');

    // set the content of the element with the ID time to the formatted string
    document.getElementById('time').innerHTML = [date, time].join(' / ');

    // call this function again in 1000ms
    setTimeout(updateClock, 1000);
}
updateClock(); // initial call


Regards,
Eduard
 
Share this answer
 
v2
Comments
Member 8387468 2-Dec-11 5:31am    
can u tell me using asp.net using C#
Try this..
JavaScript
<script type="text/javascript">
                           function show2(){
                           if (!document.all&&!document.getElementById)
                           return
                           thelement=document.getElementById? document.getElementById("tick2"): document.all.tick2
                           var Digital=new Date()
                           var hours=Digital.getHours()
                           var minutes=Digital.getMinutes()
                           var seconds=Digital.getSeconds()
                           var dn="PM"
                           if (hours<12)
                           dn="AM"
                           if (hours>12)
                           hours=hours-12
                           if (hours==0)
                           hours=12
                           if (minutes<=9)
                           minutes="0"+minutes
                           if (seconds<=9)
                           seconds="0"+seconds
                           var ctime=hours+":"+minutes+":"+seconds+" "+dn
                           thelement.innerHTML=ctime
                           setTimeout("show2()",1000)
                           }
                           window.onload=show2
                         </script>


C#
<form id="form1" runat="server">
  <div>
   <p id="tick2"></p>
  </div>
  </form>
 
Share this answer
 
Comments
Member 8387468 2-Dec-11 5:32am    
can u tell me using asp.net using c#

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900