Я пытаюсь найти разницу во времени в часах между двумя временами, но почему-то это неправильно. Может я что-то не так делаю, но не могу понять где. Разница во времени, которую я хочу, - это с определенной даты с любым временем до даты окончания в 00:00:00.
Вот как я нахожу разницу:
async function getSubscriptionValidity(org_id) {
// Get expiry date of the organisation
let validity = await Customers.findOne({ orgId: org_id }, "expiresOn -_id");
let now = moment();
let expiryDate = moment(validity.expiresOn).startOf("day");
// Calculate time remaining to expiry in hours
let difference = expiryDate.diff(now, "hours");
console.info(now);
console.info(expiryDate);
console.info(difference);
}
Результат
moment("2019-04-09T21:30:43.579") // Start Date and time
moment("2019-04-10T00:00:00.000") // End date and time
2 // Shouldn't this be 3 ?
By default, moment#diff will truncate the result to zero decimal places, returning an integer. If you want a floating point number, pass true as the third argument.