时间戳转换函数:
IM.formatDate = function(timeStamp){
var time = new Date(timeStamp);
var formatTime = time.getFullYear()+"-"+(time.getMonth()+1 < 10 ? '0'+(time.getMonth()+1) : time.getMonth()+1)
+"-"+time.getDate()+" "+time.getHours()+":"+time.getMinutes()+":"+time.getSeconds();
//var ctime = (finishdate.getSeconds()-startdate.getSeconds());
return formatTime;
};
接下来计算,单位为秒
IM.calculate = function(var stime , var ftime){
stime = Date.parse(IM.formatDate(stime));
ftime = Date.parse(IM.formatDate(ftime));
return (ftime - stime).toString().replace(/000$/ , "")+"s";
}
Date.parse("")会计算一个时间的字符串,到1970-01-01 的相差时间ms