| | |
Accessing server time using javascript
Please support our ASP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2008
Posts: 2
Reputation:
Solved Threads: 0
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???
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???
•
•
Join Date: Jan 2009
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
Hi,
You will need to create a clock in javascript that will refresh the time.
ASP Syntax (Toggle Plain Text)
protected void Page_Load(object sender, EventArgs e) {<blockquote>const string crlf = "\r\n"; string jsscript = "<script type='text/javascript'>" + crlf + "window.onload=startclock;" + crlf + "var clock;" + crlf + "var time_diff;" + crlf + "function startclock(){" + crlf + "clock=document.getElementById('clockLocal');" + crlf + "server_time = new Date('" + DateTime.Now.ToString("MMMM d, yyyy HH:mm:ss") + "');" + crlf + "time_diff=new Date()-server_time;" + crlf + "setInterval('runclock()',1000);" + crlf + "}" + crlf + "function runclock(){" + crlf + "var cDate=new Date();" + crlf + "cDate.setTime(cDate.getTime()-time_diff);" + crlf + "var curr_hours = cDate.getHours();" + crlf + "var curr_mins = cDate.getMinutes();" + crlf + "var curr_secs = cDate.getSeconds();" + crlf + "curr_hours=(curr_hours < 10)?'0' + curr_hours:curr_hours;" + crlf + "curr_mins=(curr_mins < 10)?'0' + curr_mins:curr_mins;" + crlf + "curr_secs=(curr_secs < 10)?'0' + curr_secs:curr_secs;" + crlf + "clock.innerHTML=curr_hours+':'+curr_mins+':'+curr_secs;" + crlf + "}" + crlf + "</script>";</blockquote> Page.RegisterStartupScript("ServerTimeScript", jsscript ); }
html Syntax (Toggle Plain Text)
<body onload="startclock();"> <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.
![]() |
Similar Threads
- Updated : Simple ASP.Net Login Page (ASP.NET)
- How to call Client.java from HTML? (Java)
- Connect to self... (IT Professionals' Lounge)
- Microsoft .NET FAQ (ASP.NET)
Other Threads in the ASP Forum
- Previous Thread: How to place a sql query in a javascript in an asp page
- Next Thread: Error Microsoft OLE DB/ODBC (0x80004005) Access
| Thread Tools | Search this Thread |
archive asp asp.net aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection connection database databaseconnection dreamweaver excel fso iis msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile record searchbox selectoption single specfic sqlserver sqlserverconnection windows7





