JS is run on the client script, rather than running on the server, usually, through JS acquisition time when the time is the local computer visitors time, in order to make the page on the time not because of the difference between the visitors computer, we have to direct JS access to the server time.
The following is the complete JS get the server time code, is to use JavaScript to get the full example of server time, JS dynamic refresh server time.
Thinking Analysis:
The concept of server-side time is vague. Because the server side may not be made up of a single machine after all. In the simplest case, the Web server and the DB server are also divided. What kind of a word are you talking about?
If it is a Web server.
So the direct in Java or the. NET new Date () is OK
Do not new Date in <script> inside the page, that is only the client time
If it is a DB server.
You need to connect to the database and get it through SQL. Oracle, for example, is the select Sysdate from dual.
Example:
If JS to get such a server-side time, there are many ways. The idea is roughly the same.
1.
<script type= "Text/javascript" >
var date = <%=date (the time that has been obtained on the server side, the content obtained method has been analyzed above)%>
</script>
2.<script type= "Text/javascript" src= ".../scriptservlet" ></script>
Writes the servlet's return stream to a JS file in which the var nowdate = server-side time
3.ajax, this is not said, online a lot of
The above mentioned is the entire content of this article, I hope you can enjoy.