time synchronization in html page with javascript
2011-05-04 11:29
330 查看
In some scenario, you might need the html page time been synchronized with the talking server, for example, test program for students,etc. The NTP protocol provide us the ability to synchronize our computer with internet time server, but it need native applications to do this job. In some web applications, we need accurate time. How to achieve this ?
I'm pleasure to introduce this program which will help you to solve the problem.
All we need are:
1. the javascript functions.
2. server side application.
I have implemented this program in javascript and (java)servlet, but you can do it in any other server side languages, e.g. php,perl,etc. I'll show the details.
First, the javascript functions: [simpleNTPclient.js]
**************************************************************************
Second, the servlet:[ServletSimpleNTP.java]
**************************************************************************
And now, you can use this program in you page:[demo.html]
**************************************************************************
Finally, view your html page in the browser,it should be like this:
notice:
1. "round-trip" is the time spent on the way invoking servlet.
2. "offset" is the offset between the server time and local time.
If you need this program, email me on arrenzhang@qq.com.
I'm pleasure to introduce this program which will help you to solve the problem.
All we need are:
1. the javascript functions.
2. server side application.
I have implemented this program in javascript and (java)servlet, but you can do it in any other server side languages, e.g. php,perl,etc. I'll show the details.
First, the javascript functions: [simpleNTPclient.js]
**************************************************************************
Second, the servlet:[ServletSimpleNTP.java]
**************************************************************************
And now, you can use this program in you page:[demo.html]
**************************************************************************
Finally, view your html page in the browser,it should be like this:
notice:
1. "round-trip" is the time spent on the way invoking servlet.
2. "offset" is the offset between the server time and local time.
If you need this program, email me on arrenzhang@qq.com.
相关文章推荐
- How to implement scrolling image with javascript in web page
- Creating Vista Gadgets: Using HTML, CSS and JavaScript with Examples in RSS, Ajax, ActiveX (COM) and
- how to add Javascript and CSS in page layout with sharepoint 2013
- The problems with toFixed() in JavaScript
- Trigger a button click with JavaScript on the Enter key in a text box
- Real time placement classes in javascript training in Bangalore
- How to get the HTML source of a webpage in Ruby
- how to know wether an element is exist in a html page.
- bosondata/chrome-prerender: Render JavaScript-rendered page as HTML/PDF/mhtml/png/jpeg using headless Chrome
- JavaScript中的for-in语句和with语句
- Clock Synchronization in Distributed Real Time Systems
- A guide to get you building OGRE from source with the default settings in the shortest possible time
- CallAspxPageWithJavaScript
- Tips for working with time zone in flex app
- 【每日一摩斯】-LGWR Is Generating Trace file with "Warning: Log Write Time 540ms, Size 5444kb" In 10.2.0.4
- Sample page with dom-if and dom-bind in polymer
- PhoneGap: open source development framework for building cross-platform mobile apps, Build apps in HTML and JavaScript
- [Javascript] Classify JSON text data with machine learning in Natural
- Detect CSS3 Support in Browsers with JavaScript
- Generate Android testing reports in XML/HTML with Android CTS