Asp+js code to obtain and display the server time in real time

Source: Internet
Author: User
Tags date
asp+|js| Server | display

  The first type of code:

<script language=javascript type= "Text/javascript" >
Special note: Beijing time is Greenwich Standard PLUS eight hours, so the starting time is also starting from eight points
var secondserver = <%=datediff ("s", "1970-01-01 08:00:00", Now ())%>;
var secondclient = parseint (new Date (). GetTime ()/1000);
var secondsub = secondserver-secondclient; Both ends time seconds difference
function Meizztime (n)
{
var Mei = new Date ();
Mei.settime (Mei.gettime () + n*1000); To get a new time
var h = (Mei.gethours () > 9)? Mei.gethours (): "0" + mei.gethours ();
var m = (Mei.getminutes () > 9)? Mei.getminutes (): "0" + mei.getminutes ();
var s = (Mei.getseconds () > 9)? Mei.getseconds (): "0" + mei.getseconds ();
Document.meizz.clock.value = "" "+ H +": "+ M +": "+ S +" "";
SetTimeout ("Meizztime (secondsub)", 1000);
}
</script>
<meta http-equiv= ' content-type ' content= ' text/html; charset=gb2312 ' >
<meta http-equiv= "Refresh" content= "1000" >
<title>javascript + ASP to obtain and real-time display server time </title>
<style type= "Text/css" >
<!--
Body {
margin-left:0px;
margin-top:0px;
margin-right:0px;
margin-bottom:0px;
}
-->
</style>
<style type= "Text/css" >
<!--
. form {
Font-family:verdana,arial, Helvetica;
font-size:9pt; Color: #000000;
height:18px;
line-height:14px;
Background:none;
Border:none;
}
-->
</style>
<body >
<form name= "Meizz" >
<input name= "Clock" size= "class=" "Form" >
</form>
</body>

  Another type of code:

<script language=javascript type= "Text/javascript" >
Special note: Beijing time is Greenwich Standard PLUS eight hours, so the starting time is also starting from eight points
var secondserver = <%=datediff ("s", "1970-01-01 08:00:00", Now ())%>;
var secondclient = parseint (new Date (). GetTime ()/1000);
var secondsub = secondserver-secondclient; Both ends time seconds difference
Week function
function Initarray () {
This.length=initarray.arguments.length
for (Var i=0;i<this.length;i++)
This[i+1]=initarray.arguments[i]
}
function Meizztime (n)
{
var Mei = new Date ();
Mei.settime (Mei.gettime () + n*1000); To get a new time
var y = mei.getyear ();//year
var t = mei.getmonth () +1;//need to add 1
var d = mei.getdate ();//day
var w = new Initarray (
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday");
var z = w[mei.getday () +1]//Week
var h = (Mei.gethours () > 9)? Mei.gethours (): "0" + mei.gethours (); When
var m = (Mei.getminutes () > 9)? Mei.getminutes (): "0" + mei.getminutes (); Part
var s = (Mei.getseconds () > 9)? Mei.getseconds (): "0" + mei.getseconds (); Seconds
Document.meizz.clock.value = y + "Year" + T + "month" + D + "Day" + z + "" + H + ":" + M + ":" + S; Show date and time
SetTimeout ("Meizztime (secondsub)", 1000);
}
</script>
<meta http-equiv= ' content-type ' content= ' text/html; charset=gb2312 ' >
<meta http-equiv= "Refresh" content= "1000" >
<title>javascript + ASP to obtain and real-time display server time </title>
<style type= "Text/css" >
<!--
Body {
margin-left:0px;
margin-top:0px;
margin-right:0px;
margin-bottom:0px;
}
-->
</style>
<style type= "Text/css" >
<!--
. form {
Font-family:verdana,arial, Helvetica;
font-size:9pt; Color: #000000;
height:18px;
line-height:14px;
Background:none;
Border:none;
}
-->
</style>
<body >
<form name= "Meizz" >
<input name= "Clock" size= "class=" "Form" >
</form>
</body>
Because I do not have ASP space, so only everyone test themselves!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.