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

## How many seconds have passed today?

الأهمية: 5

Write a function `getSecondsToday()` that returns the number of seconds from the beginning of today.

For instance, if now were `10:00 am`, and there was no daylight savings shift, then:

``getSecondsToday() == 36000 // (3600 * 10)``

The function should work in any day. That is, it should not have a hard-coded value of “today”.

To get the number of seconds, we can generate a date using the current day and time 00:00:00, then substract it from “now”.

The difference is the number of milliseconds from the beginning of the day, that we should divide by 1000 to get seconds:

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

// create an object using the current day/month/year
let today = new Date(now.getFullYear(), now.getMonth(), now.getDate());

let diff = now - today; // ms difference
return Math.round(diff / 1000); // make seconds
}

``````function getSecondsToday() {