话不多说直接上代码
var cur_time = new Date();
var old_time = new Date('2021-07-01 08:30:00');
var difftime = (cur_time - old_time) / 1000; //秒
var days = parseInt(difftime / 86400); //天 24*60*60*1000
var hours = parseInt(difftime / 3600) - 24 * days; // 小时