943,909 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Unsolved
  • Views: 3355
  • ASP RSS
Aug 11th, 2008
0

Accessing server time using javascript

Expand Post »
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???
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chkchelsea is offline Offline
2 posts
since Aug 2008
Aug 11th, 2008
0

Re: Accessing server time using javascript

Hi,

You will need to create a clock in javascript that will refresh the time.
Reputation Points: 28
Solved Threads: 19
Junior Poster
vicky_rawat is offline Offline
137 posts
since Jun 2008
Aug 11th, 2008
0

Re: Accessing server time using javascript

that i noe... but how to do it???
Reputation Points: 10
Solved Threads: 0
Newbie Poster
chkchelsea is offline Offline
2 posts
since Aug 2008
Jan 16th, 2009
0

Re: Accessing server time using javascript

Hi,

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


ASP Syntax (Toggle Plain Text)
  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
html Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
suraj145 is offline Offline
1 posts
since Jan 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: How to place a sql query in a javascript in an asp page
Next Thread in ASP Forum Timeline: Books for ASP Noobs?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC