// var Date1 = "2003-06-17";
// var Date2 = "2004-09-18";
var Date1 = "2004-09-17 03:03:40.";
var Date2 = "2004-09-18 12:03:12.";
Date1=Date1.substring(0,Date1.lastIndexOf(".")).replace(/-/g,"/");
Date2=Date2.substring(0,Date2.lastIndexOf(".")).replace(/-/g,"/");
// Date1=Date1.replace(/-/g,"/");
// Date2=Date2.replace(/-/g,"/");
var date1 = Date.parse(Date1);
var date2 = Date.parse(Date2);
// alert("Date2与Date1相差"+Math.ceil((date2-date1)/(24*60*60*1000))+"天");
alert("Date2与Date1相差"+Math.ceil((date2-date1)/(60*60*1000))+"小時");
alert("Date2与Date1相差"+Math.floor((date2-date1)/(60*60*1000))+"小時");
}
//當前時間減去輸入的時間 時間格式為2004-09-17 03:03:40. 最後有一點
function textTime(uptime){
var myDate = new Date();
var y=myDate.getFullYear();
var M=myDate.getMonth()+1;
var d=myDate.getDate();
var h=myDate.getHours();
var m=myDate.getMinutes();
var s=myDate.getSeconds();
var nowTime=y+"-"+M+"-"+d+" "+h+":"+m+":"+s+".";
strDate1 = uptime+".";
strDate1=strDate1.substring(0,strDate1.lastIndexOf(".")).replace(/-/g,"/");
nowTime=nowTime.substring(0,nowTime.lastIndexOf(".")).replace(/-/g,"/");
var date1 = Date.parse(strDate1);
var date2 = Date.parse(nowTime);
var getDay=Math.floor((date2-date1)/(24*60*60*1000));
var getHours=Math.floor((date2-date1)/(60*60*1000));
var getM=Math.floor((date2-date1)/(60*1000));
if(getDay>0){
return getDay+"天";
}else if(getHours>0){
return getHours+"小時";
}else {
return getM+"分鐘";
}
}
//将转换为parse转换为字符串的转换为Date
var date1 = Date.parse(strDate1);
var ddddd=new Date(date1);