Alternative solution

This commit is contained in:
Brent Guffens 2018-01-27 17:32:38 +01:00 committed by GitHub
parent 13be80afb9
commit 02942eb420
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,3 +13,19 @@ function getSecondsToTomorrow() {
return Math.round(diff / 1000); // convert to seconds return Math.round(diff / 1000); // convert to seconds
} }
``` ```
Alternative solution:
```js run
function getSecondsToTomorrow() {
let now = new Date();
let hour = now.getHours();
let minutes = now.getMinutes();
let seconds = now.getSeconds();
let totalSecondsToday = (hour * 60 + minutes) * 60 + seconds;
let totalSecondsInADay = 86400;
return totalSecondsInADay - totalSecondsToday;
}
```