الرجوع الي الدرس
هذة المادة العلميه متاحه فقط باللغات الأتيه: English, Español, 日本語, 한국어, Русский, 简体中文. من فضلك, ساعدنا قم بالترجمه إلى عربي.

## How many seconds till tomorrow?

الأهمية: 5

Create a function `getSecondsToTomorrow()` that returns the number of seconds till tomorrow.

For instance, if now is `23:00`, then:

``getSecondsToTomorrow() == 3600``

P.S. The function should work at any day, the “today” is not hardcoded.

To get the number of milliseconds till tomorrow, we can from “tomorrow 00:00:00” substract the current date.

First, we generate that “tomorrow”, and then do it:

``````function getSecondsToTomorrow() {
let now = new Date();

// tomorrow date
let tomorrow = new Date(now.getFullYear(), now.getMonth(), now.getDate()+1);

let diff = tomorrow - now; // difference in ms
return Math.round(diff / 1000); // convert to seconds
}``````

Alternative solution:

``````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;