Update and rename getDifferenceInSeconds.md to getSecondsDiffBetweenDates.md

This commit is contained in:
Isabelle Viktoria Maciohsek
2021-04-24 12:39:48 +03:00
committed by GitHub
parent a7309e5754
commit 65bfb333eb
2 changed files with 20 additions and 15 deletions

View File

@ -1,15 +0,0 @@
---
title: getDifferenceInSeconds
tags: dates,beginner
---
Returns the diffrence in seconds between 2 supplied dates.
```js
const getDifferenceInSeconds = (start, end) =>
(end.getTime() - start.getTime()) / 1000;
```
```js
getDifferenceInSeconds(new Date('2020-12-24 00:00:15'), new Date('2020-12-24 00:00:17')); // 2
```

View File

@ -0,0 +1,20 @@
---
title: getSecondsDiffBetweenDates
tags: date,beginner
---
Calculates the difference (in seconds) between two dates.
- Subtract the two `Date` objects and divide by the number of milliseconds in a second to get the difference (in seconds) between them.
```js
const getSecondsDiffBetweenDates = (dateInitial, dateFinal) =>
(dateFinal - dateInitial) / 1000;
```
```js
getSecondsDiffBetweenDates(
new Date('2020-12-24 00:00:15'),
new Date('2020-12-24 00:00:17')
); // 2
```