Display the server time and refresh every 1 sec using Javascript in asp.net
-
Hi all, I want to display the server time and refresh the time every 1 sec using javascript in asp.net but it showing client time when page is runing. So any one can help me to sort out this problem. Thanks in advance... Regards, G Mariappan
-
Hi all, I want to display the server time and refresh the time every 1 sec using javascript in asp.net but it showing client time when page is runing. So any one can help me to sort out this problem. Thanks in advance... Regards, G Mariappan
-
Javascript runs in the client browser, so will reflect the client's timezone. You need to use a mechanism (code behind, AJAX?) to get the data from the server.
Veni, vidi, abiit domum
Hi Richard, Thanks for your reply i used javascript to get the server time please see the below code its works for me //Users time var timeLocal = new Date(); var timeServer = new Date('<%= DateTime.Now.ToString()%>'); //Calculate the difference (returns milliseconds) millDiff = timeLocal - timeServer; //initalize the clock on loading of page window.onload = function () { //set the interval so clock ticks var timeClock = setInterval("TimeTick()", 1000); } //The ticking clock function function TimeTick() { //grab updated time timeLocal = new Date(); //add time difference timeLocal.setMilliseconds(timeLocal.getMilliseconds() - millDiff); document.getElementById("lblserverTime")=timeLocal; This code working fine for me...</x-turndown>
-
Hi all, I want to display the server time and refresh the time every 1 sec using javascript in asp.net but it showing client time when page is runing. So any one can help me to sort out this problem. Thanks in advance... Regards, G Mariappan
I think you know java script is work on client side. I think ajax control will be help you.