Navigate back to the homepage

How to get seconds between two dates in javascript

Infinitbility
JavaScript
August 28th, 2021 · 1 min read
How to get seconds between two dates in javascript

Hello Friends 👋,

Welcome To Infinitbility! ❤️

Manytimes for analytics we have to calculate time difference between user start using feature and user end using feature.

We have to both date object and using getTime() function take both date time and subtract time2 to time 1.

In below example, First we create two objects and store in variable and when we substract dates and divide by 1000 then we will get difference in seconds.

1var t1 = new Date("2021-08-25 07:41:07");
2var t2 = new Date("2021-08-25 07:50:07");
3var dif = ( t2.getTime() - t1.getTime() ) / 1000;
4console.log(dif)

Thanks for reading…

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Tutorials

React Native

Categories

More articles from Infinitbility

How to detect screen lock set or not in react native

How to detect screen lock set or not in react native

React Native DeviceInfo isPinOrFingerprintSet example

August 27th, 2021 · 1 min read
Error while adding new header in apache2

Error while adding new header in apache2

how to solve invalid command 'Header' in apache2

August 25th, 2021 · 1 min read
© 2020–2021 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]