Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I'm doing an attendance system and face a problem to get the server time show in javascript. It was an error since the server time is not same as the local time. This problem occurs when user click the button and get server time add to database, it is no problem save the time to database, but it will confuse :confused: the user if local time is not same as the server time.

 

Anyone have an idea or snippets to solve the problem. I got a lot of sample code of javascript by all get in local time. I need it get from server time. A lot of people said javascript cannot do such function, but i believe that there are another approach to solve such problem.

 

For those comments and suggestions will more appreciate. :)

 

Calvin

  • Moderators
Posted
As kahlua001 said; ask the user for their timezone. Also, if there is a login process or some sort of user profile setup for each user you can save their timezone as an integer from GMT.
Visit...Bassic Software
Posted

Got Solution

 

Code behind

Response.Write("<script>var timeServer = new Date('" + DateTime.Now.ToString() + "');</script>");

 

Client Side code

<script type="text/javascript">

 

//Users time

var timeLocal = new Date();

 

//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()",10);

}

 

//The ticking clock function

function TimeTick(){

//grab updated time

timeLocal = new Date();

//add time difference

timeLocal.setMilliseconds(timeLocal.getMilliseconds() - millDiff);

//display the value

document.getElementById("spanTime").innerHTML =timeLocal;

}

 

</script>

<span id="spanTime"></span>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...