Remaining Time (Countdown) for Taobao

Source: Internet
Author: User

1. <SCRIPT language = JavaScript>
Var auctionDate = 120;
Var startTime = (new Date (). getTime ();
Var Temp;
Var timerID = null;
Var timerRunning = false;
Function showtime ()
{
Now = new Date ();
Var ts = parseInt (startTime-now.getTime ()/1000) + auctionDate;
Var dateLeft = 0;
Var hourLeft = 0;
Var minuteLeft = 0;
Var secondLeft = 0;
If (ts <0)
{
Ts = 0;
CurHour = 0;
CurMinute = 0;
CurSecond = 0;
} Else {
DateLeft = parseInt (ts/86400 );
Ts = ts-dateLeft * 86400;
HourLeft = parseInt (ts/3600 );
Ts = ts-hourLeft * 3600;
MinuteLeft = parseInt (ts/60 );
SecondLeft = ts-minuteLeft * 60;
}
If (hourLeft <10) hourLeft = '0' + hourLeft;
If (minuteLeft <10) minuteLeft = '0' + minuteLeft;
If (secondLeft <10) secondLeft = '0' + secondLeft;
If (dateLeft> 0)
DateLeft = dateLeft + "day ";
Else
DateLeft = "";
If (hourLeft> 0)
HourLeft = hourLeft + "Hour ";
Else
{
If (dateLeft! = "")
HourLeft = "00 hours ";
Else
HourLeft = "";
}
If (minuteLeft> 0)
MinuteLeft = minuteLeft + "min ";
Else
{
If (dateLeft! = "" | HourLeft! = "")
MinuteLeft = "00 minutes ";
Else
MinuteLeft = "";
}
If (secondLeft> 0)
SecondLeft = secondLeft + "seconds ";
Else
{
If (dateLeft! = "" | HourLeft! = "" | MinuteLeft! = "")
SecondLeft = "00 seconds ";
Else
SecondLeft = "";
}
If (dateLeft = ''){
Temp = dateLeft + hourLeft + minuteLeft + secondLeft;
} Else {
Temp = dateLeft + hourLeft;
}
If (dateLeft <= 0 & hourLeft <= 0 & minuteLeft <= 0 & secondLeft <= 0)
{
Temp = "deal concluded ";
Stopclock ();
}
If (document. getElementById ('time2') document. getElementById ('time2'). innerHTML = Temp;
TimerID = setTimeout ("showtime ()", 1000 );
TimerRunning = true;
}
Function stopclock ()
{
If (timerRunning)
ClearTimeout (timerID );
TimerRunning = false;
}
Function macauclock ()
{
Stopclock ();
Showtime ();
}
Function onloadall ()
{
Macauclock ();
Try
{
Initprovcity ();
}
Catch (e)
{
}
}
Try
{
Onload = onloadall ();
}
Catch (e)
{
}
</SCRIPT>
Write the remaining seconds in <font id = "time2"> 18595 </font> when generating the page.

 

2. function go ()
{
//
// NowTime
//
Now = new Date ();
Var Time = "";
Var h = now. getHours ();
Time = h + ":";

Var m = now. getMinutes ()
If (m <10)
Time = Time + "0" + m + ":";
Else
Time + = m + ":";

Var s = now. getSeconds ();
If (s <10)
Time = Time + "0" + s;
Else
Time + = s;
Document. Form1.nowTime. value = Time;
//
// Leave time 70 mintes, | have 00:17:34, leave 00:52:26 | have 01:04:46, leave 53: 00 | --->
// Consider the hour
//
Time = (now. getTime ()-start. getTime ()/1000;
Time = Math. floor (time); // remove the number of decimal places and keep the integer
//
// 00:00:00, that is, the remaining time must be greater than or equal to examTime
//
If (time> = examTime * 60)
{
Alert ("the exam time is up !! ")
GetAunwsers ();
}

HaveS = time % 60;
HaveM = Math. floor (time/60 );

Var leaveH;
Var leaveM;
Var leaveS;
//
If (haveS = 0)
{
LeaveM = examTime-haveM;
LeaveH = Math. floor (leaveM/60 );
If (leaveM <10)
Document. Form1.leaveTime. value = "0" + leaveH + ":" + "0" + leaveM + ": 00"
Else
Document. Form1.leaveTime. value = "0" + leaveH + ":" + leaveM + ": 00"
}
Else
{
LeaveS = 60-haveS;
If (leaveS <10)
S = "0" + leaveS;
Else
S = leaveS;
LeaveM = examTime-haveM-1;
//
LeaveH = Math. floor (leaveM/60 );

If (leaveM <10)
Document. Form1.leaveTime. value = "0" + leaveH + ":" + "0" + leaveM + ":" + s;
Else
Document. Form1.leaveTime. value = "0" + leaveH + ":" + leaveM + ":" + s;
}
SetTimeout ("go ()", 1000 );
}

//
// SetExamTime
//
Start = new Date ();
// Document. Form1.toTime. value is a character type and must be converted to an integer value.
Var examTime = parseInt (document. Form1.toTime. value, 10 );

Function setExamTime ()
{
//
// StartTime
//
Var Time = "";
Var h = start. getHours ();
Time = h + ":";

Var m = start. getMinutes ()
If (m <10)
Time = Time + "0" + m + ":";
Else
Time + = m + ":";

Var s = start. getSeconds ();
If (s <10)
Time = Time + "0" + s;
Else
Time + = s;

Document. Form1.startTime. value = Time;
// This sentence cannot be added. I don't know why
// Document. Form1.toTime. value = "Minute ";
//
// EndTime
//
If (examTime + m> = 60)
{

If (h = 24)
H = 1;
Else
H + = 1;
M = examTime + M-60;
}
Else
{
M = examTime + m
}
//
Time = h + ":";
If (m <10)
Time + = "0" + m + ":";
Else
Time + = m + ":";
If (s <10)
Time + = "0" + s;
Else
Time + = s;
Document. Form1.endTime. value = Time;
//
//
//
Go ();
}
Function go ()
{
//
// NowTime
//
Now = new Date ();
Var Time = "";
Var h = now. getHours ();
Time = h + ":";

Var m = now. getMinutes ()
If (m <10)
Time = Time + "0" + m + ":";
Else
Time + = m + ":";

Var s = now. getSeconds ();
If (s <10)
Time = Time + "0" + s;
Else
Time + = s;
Document. Form1.nowTime. value = Time;
//
// Leave time 70 mintes, | have 00:17:34, leave 00:52:26 | have 01:04:46, leave 53: 00 | --->
// Consider the hour
//
Time = (now. getTime ()-start. getTime ()/1000;
Time = Math. floor (time); // remove the number of decimal places and keep the integer
//
// 00:00:00, that is, the remaining time must be greater than or equal to examTime
//
If (time> = examTime * 60)
{
Alert ("the exam time is up !! ")
GetAunwsers ();
}

HaveS = time % 60;
HaveM = Math. floor (time/60 );

Var leaveH;
Var leaveM;
Var leaveS;
//
If (haveS = 0)
{
LeaveM = examTime-haveM;
LeaveH = Math. floor (leaveM/60 );
If (leaveM <10)
Document. Form1.leaveTime. value = "0" + leaveH + ":" + "0" + leaveM + ": 00"
Else
Document. Form1.leaveTime. value = "0" + leaveH + ":" + leaveM + ": 00"
}
Else
{
LeaveS = 60-haveS;
If (leaveS <10)
S = "0" + leaveS;
Else
S = leaveS;
LeaveM = examTime-haveM-1;
//
LeaveH = Math. floor (leaveM/60 );

If (leaveM <10)
Document. Form1.leaveTime. value = "0" + leaveH + ":" + "0" + leaveM + ":" + s;
Else
Document. Form1.leaveTime. value = "0" + leaveH + ":" + leaveM + ":" + s;
}
SetTimeout ("go ()", 1000 );
}
SetExamTime ();
-----------------------------------------------------------------
<Div id = "myleft" style = "Z-INDEX: 1; RIGHT: 5px; VISIBILITY: visible; WIDTH: 150px; POSITION: absolute; TOP: 300px">
<Table id = "setTable" cellSpacing = "0" cellPadding = "0" width = "150" bgColor = "# ffffcc" border = "0">
<Tr>
<Td align = "center" colSpan = "2"> clock table </td>
</Tr>
<Tr>
<Td width = "65"> Start Time: </td>
<Td width = "85"> <input readOnly type = "text" size = "10" name = "startTime"> </td>
</Tr>
<Tr>
<Td> End Time: </td>
<Td> <input readOnly type = "text" size = "10" name = "endTime"> </td>
</Tr>
<Tr>
<Td> test time: </td>
<Td> <input id = "toTime" readOnly type = "text" size = "10" name = "toTime" runat = "server"> </td>
<Tr>
<Td D> current time: </td>
<Td> <input readOnly type = "text" size = "10" name = "nowTime"> </td>
</Tr>
<Tr>
<Td D> remaining time: </td>
<Td> <input readOnly type = "text" size = "10" name = "leaveTime"> </td>
</Tr>
<Tr>
<Td align = "center" colSpan = "2"> <br>
<Input id = "btnOK" onclick = "getAunwsers ()" type = "submit" value = "End exam">
</Td>
</Tr>
</Table>
</Div>

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.