这些是我的变量;
var start = "10:20 AM";
var end = "10:30 AM";
我想在几分钟内找到时差。我怎么能这样做?
答案 0 :(得分:0)
试试这个
var start = "10:20 AM";
var end = "10:30 AM";
// convert into something like a unix timestamp by adding a date
start = new Date('01.01.1970 '+start).getTime() / 1000;
end = new Date('01.01.1970 '+end).getTime() / 1000;
// time diff in minutes
var result = Math.abs(end - start) / 60;
答案 1 :(得分:0)
我建议使用momentjs来处理日期/时间,这会有很大帮助。 ;)
var diff = moment(end, 'HH:mm A').diff(moment(start, 'HH:mm A'), 'minutes');