Date.prototype.diff = function(date){
return (this.getTime() - date.getTime())/(24 * 60 * 60 * 1000)
}
// 构造两个日期,分别是系统时间和2013/04/08 12:43:45
var now = new Date()
var date = new Date('2013/04/08 12:43:45')
// 调用日期差方法,求得参数日期与系统时间相差的天数
var diff = now.diff(date)
// 打印日期差
alert(diff)
转为 DATE() 类型 直接相减 得出毫秒数 除1000 得秒数 除60000 得分钟数
var d1 = new Date('2016/03/28 10:17:22')var d2 = new Date('2016/03/28 11:17:22')
console.log(parseInt(d2 - d1))//两个时间相差的毫秒数
console.log(parseInt(d2 - d1) / 1000)//两个时间相差的秒数
console.log(parseInt(d2 - d1) / 6000 )//两个时间相差的分钟数
console.log(parseInt(d2 - d1) / 3600000 )//两个时间相差的小时数