我想计算时间之间的差异,但我不知道该怎么做。首先,我从数据库中检索时间后得到当前的数据。我不知道如何创建一个方程来计算它们。
//get the time
h = now.getHours();
m = now.getMinutes();
if (h < 10)
h = '0' + h;
if (m < 10)
m = '0' + m;
var timestring = h + ":" + m;
var query = firebaseRef.orderByChild('carplate').equalTo(carplate);
query.once('value', function(snapshot) {
snapshot.forEach(function(child) {
var time = child.val().time;
var diff = timestring - time; //how to calculate the different
})
});
使用Date.now()
将时间存储为UTC时间戳。只需从较大的较小值中减去较小值即可。将用户可读的时间格式化为UI用途。