Accessing server time using javascript

Reply

Join Date: Aug 2008
Posts: 2
Reputation: chkchelsea is an unknown quantity at this point 
Solved Threads: 0
chkchelsea chkchelsea is offline Offline
Newbie Poster

Accessing server time using javascript

 
0
  #1
Aug 11th, 2008
Hi,

I have a problem accessing server time using javascript. I'm making a home page in asp and want to access server time using javascript. What i'm doing presently is accessing server time in vbscript, and now want to display this in a javascript calendar which i hav already made. Now the thing left is displaying time and also refreshing it without refreshing whole page. Can any body help. I know how to do for SSI and PHP pages. But want to try in ASP page. Can nybody suggest???
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 133
Reputation: vicky_rawat is an unknown quantity at this point 
Solved Threads: 17
vicky_rawat's Avatar
vicky_rawat vicky_rawat is offline Offline
Junior Poster

Re: Accessing server time using javascript

 
0
  #2
Aug 11th, 2008
Hi,

You will need to create a clock in javascript that will refresh the time.
Vivek Rawat
Keep solving complexities.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 2
Reputation: chkchelsea is an unknown quantity at this point 
Solved Threads: 0
chkchelsea chkchelsea is offline Offline
Newbie Poster

Re: Accessing server time using javascript

 
0
  #3
Aug 11th, 2008
that i noe... but how to do it???
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1
Reputation: suraj145 is an unknown quantity at this point 
Solved Threads: 0
suraj145 suraj145 is offline Offline
Newbie Poster

Re: Accessing server time using javascript

 
0
  #4
Jan 16th, 2009
Originally Posted by vicky_rawat View Post
Hi,

You will need to create a clock in javascript that will refresh the time.
//Code behind


  1. protected void Page_Load(object sender, EventArgs e)
  2. {<blockquote>const string crlf = "\r\n";
  3. string jsscript = "<script type='text/javascript'>" + crlf +
  4. "window.onload=startclock;" + crlf +
  5. "var clock;" + crlf +
  6. "var time_diff;" + crlf +
  7. "function startclock(){" + crlf +
  8. "clock=document.getElementById('clockLocal');" + crlf +
  9. "server_time = new Date('" + DateTime.Now.ToString("MMMM d, yyyy HH:mm:ss") + "');" + crlf +
  10. "time_diff=new Date()-server_time;" + crlf +
  11. "setInterval('runclock()',1000);" + crlf +
  12. "}" + crlf +
  13. "function runclock(){" + crlf +
  14. "var cDate=new Date();" + crlf +
  15. "cDate.setTime(cDate.getTime()-time_diff);" + crlf +
  16. "var curr_hours = cDate.getHours();" + crlf +
  17. "var curr_mins = cDate.getMinutes();" + crlf +
  18. "var curr_secs = cDate.getSeconds();" + crlf +
  19. "curr_hours=(curr_hours < 10)?'0' + curr_hours:curr_hours;" + crlf +
  20. "curr_mins=(curr_mins < 10)?'0' + curr_mins:curr_mins;" + crlf +
  21. "curr_secs=(curr_secs < 10)?'0' + curr_secs:curr_secs;" + crlf +
  22. "clock.innerHTML=curr_hours+':'+curr_mins+':'+curr_secs;" + crlf +
  23. "}" + crlf +
  24. "</script>";</blockquote> Page.RegisterStartupScript("ServerTimeScript", jsscript );
  25.  
  26. }
//ASPX page
  1. <body onload="startclock();">
  2. <span id=clockLocal style="position:relative;"></span>
Last edited by peter_budo; Jan 18th, 2009 at 2:34 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC