startclock()
var timerID = null;
var timerRunning = false;
var year = "";
var month= "";
var day= "";
var hour= "";
var minute= "";
var seconds= "";
function showtime() {
var time=$("#hiddenTime").val();
splitTime(time);//以上用于截取时间,分成年,月,日,时,分,秒
//=========================================
//以下用于用于计算时间差
Today = new Date();
var NowHour = Today.getHours();
var NowMinute = Today.getMinutes();
var NowMonth = Today.getMonth();
var NowDate = Today.getDate();
var NowYear = Today.getYear();
var NowSecond = Today.getSeconds();
if (NowYear < 2000)
NowYear = 1900 + NowYear;
Today = null;
Hourleft = hour - NowHour
Minuteleft = minute - NowMinute
Secondleft = seconds - NowSecond
Yearleft = year - NowYear
Monthleft = month - NowMonth - 1
Dateleft = day - NowDate
if (Secondleft < 0) {
Secondleft = 60 + Secondleft;
Minuteleft = Minuteleft - 1;
}
if (Minuteleft < 0) {
Minuteleft = 60 + Minuteleft;
Hourleft = Hourleft - 1;
}
if (Hourleft < 0) {
Hourleft = 24 + Hourleft;
Dateleft = Dateleft - 1;
}
if (Dateleft < 0) {
Dateleft = 31 + Dateleft;
Monthleft = Monthleft - 1;
}
if (Monthleft < 0) {
Monthleft = 12 + Monthleft;
Yearleft = Yearleft - 1;
}
Temp = Dateleft + '天, '
+ Hourleft + '小时, ' + Minuteleft + '分, ' + Secondleft + '秒'
$("#timeup").html(Temp);
timerID = setTimeout("showtime()", 1000);
timerRunning = true;
}
var timerID = null;
var timerRunning = false;
function stopclock() {
if (timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function startclock() {
stopclock();
showtime(); //调用计算时间差方法,并显示
}
//以上用于计算时间差
//=============================================
function splitTime(time){
year=time.substr(0,4);
var index1=time.indexOf("-");
var index2=time.lastIndexOf("-");
var cha=parseInt(index2)-(parseInt(index1)+1);
month=time.substr((parseInt(index1)+1),cha);
var kg=time.indexOf(" ");
cha=parseInt(kg)-parseInt(index2);
day=time.substr(parseInt(index2)+1,cha);
var mh=time.indexOf(":");
cha=parseInt(mh)-(parseInt(kg)+1);
hour=time.substr(parseInt(kg)+1,cha);
var mh2=time.lastIndexOf(":");
cha=parseInt(mh2)-(parseInt(mh)+1);
minute=time.substr(parseInt(mh)+1,cha);
var mh2=time.lastIndexOf(":");
seconds=time.substr(parseInt(mh2)+1,2);
}