js日期相减函数

来源:互联网 发布:java future get 超时 编辑:程序博客网 时间:2024/05/20 08:41
//返回相差豪秒数
function dateDiff(oldDate,newDate){
oldDate = oldDate.replace(/-/g,"/");
newDate = newDate.replace(/-/g,"/");
var date1 = new Date(oldDate);
var date2 = new Date(newDate);
return (date2-date1);//除以1000毫秒,60秒,60分,剩下的就是小时
}

//获取系统当前时间并格式化 yyyy-mm-dd HH:mm:ss
function getSysTime(){
var newDate = new Date();
return newDate.getFullYear()
+"-"+(newDate.getMonth()+1)
+"-"+newDate.getDate()
+" "+newDate.getHours()
+":"+newDate.getMinutes()
+":"+newDate.getSeconds();
}
0 0
原创粉丝点击