我想计算时间之间的差异,但我不知道该怎么做。首先我得到电流,然后我从数据库中检索时间。我不知道如何创建一个方程式来计算它们。
//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 目的将时间格式化为人类可读。
关于javascript - 如何计算两个时间的差异?一个在 firebase 中,一个是当前时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49114222/