Example of the number of seconds since the last refresh in JS

Source: Internet
Author: User

Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
<Script src = "http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"> </script>
<Script type = "text/javascript">
$ (Function (){
// JQuery code

Var oldhh;
Var oldmin;
Var oldss;

$ (Document). ready (function (){
FillDate ();
});
Function fillDate (){
Var date = new Date ();
Var yy = date. getFullYear ();
Var mm = date. getMonth () + 1; // truncate month,
Var dd = date. getDate (); // truncate the day,
Var cal = yy + "." + mm + "." + dd;
Var hh = date. getHours (); // intercept the hour,
Var min = date. getMinutes (); // capture minutes,

Var ss = date. getTime () %60000;
Ss = (ss-(ss % 1000)/1000; // then, the number of milliseconds is processed into seconds.
// (Hh + ":" + min + ":" + ss );
Oldhh = hh;
Oldmin = min;
Oldss = ss;
// Alert (oldmin + ":" + oldss );
}
Window. setInterval (test, 1000 );
Function test (){
Var date = new Date ();
Var hh = date. getHours (); // intercept the hour, that is, 8
Var min = date. getMinutes (); // capture minutes, that is, 34
Var ss = date. getTime () %60000;
Ss = (ss-(ss % 1000)/1000; // then, the number of milliseconds is processed into seconds.
Var betweenhh;
Var betweenmin;
Var betweenss;

If (ss <oldss ){
Betweenss = ss + 60-oldss;
Betweenhh = hh-oldhh;
Betweenmin = (min + betweenhh * 60)-1-oldmin;


// Alert ("Last refresh" + betweenmin + "Minute" + betweenss + "second ");
} Else {
Betweenss = ss-oldss;
Betweenhh = hh-oldhh;
Betweenmin = (min + betweenhh * 60)-oldmin;
// $ ("# Message" ).html ("Last refresh" + betweenmin + "Minute" + betweenss + "second ");
// Alert ("Last refresh" + betweenmin + "Minute" + betweenss + "second ");
}
If (betweenmin <10 ){
If (betweenss <10 ){
$ ("# Message" ).html ("0 from last refresh" + betweenmin + "0" + betweenss + "second ");
} Else {
$ ("# Message" ).html ("0 from last refresh" + betweenmin + "Minute" + betweenss + "second ");
}

} Else {
If (betweenss <10 ){
$ ("# Message" ).html ("Last refresh" + betweenmin + "0" + betweenss + "second ");
} Else {
$ ("# Message" ).html ("Last refresh" + betweenmin + "Minute" + betweenss + "second ");
}
}
}
});
Function ByStateflag ()
{
Alert ("hah ");
Var value = document. getElementById ("stateflag"). value;
Alert (value );
}
</Script>
</Head>
<Body>
<Div id = "message">

</Div>
<Select id = "stateflag" name = "stateflag" onchange = "ByStateflag ()">
<Option selected value = ""> Transaction Status </option>
<Option value = "0"> in progress </option>
<Option value = "1"> terminate a transaction </option>
<Option value = "3"> the buyer has locked the goods </option>
<Option value = "4"> payment by buyer </option>
<Option value = "5"> transaction completed </option>
</Select>

</Body>
</Html>

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.