关于两个日期之间的

来源:互联网 发布:大话西游男鬼加点数据 编辑:程序博客网 时间:2024/06/05 23:54

时间戳转换函数:

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

原创粉丝点击