-3

I am looking for something in the specific format. The once that you linked are between dates. I am mechanical engineer working to get time spent for my machines and it can range from seconds to hours.

Format of the time spent:

2021-10-07T12:44:10-0700 ---- 2021-10-07T12:47:12-0700

lucifer
  • 1
  • 2
  • 3
    Does this answer your question? [Get time difference between two dates in seconds](https://stackoverflow.com/questions/13894632/get-time-difference-between-two-dates-in-seconds) or [Get difference between 2 dates in JavaScript?](https://stackoverflow.com/questions/3224834/get-difference-between-2-dates-in-javascript) or [How do I get the number of days between two dates in JavaScript?](https://stackoverflow.com/questions/542938/how-do-i-get-the-number-of-days-between-two-dates-in-javascript) – pilchard Oct 07 '21 at 23:39
  • I am looking for something in the specific format. The once that you linked are between dates. I am mechanical engineer working to get time spent for my machines and it can range from seconds to hours. – lucifer Oct 07 '21 at 23:44
  • The duplicates have ample answers covering everything from ms to years, so surely you can find something to build off of. You haven't showed any effort to solve this yourself in your question, nor any indication that you've read the *many* answers in the linked duplicates. – pilchard Oct 07 '21 at 23:53
  • Please provide enough code so others can better understand or reproduce the problem. – Community Oct 11 '21 at 19:22

1 Answers1

-1
const str1 = '2021-10-07T12:44:10-0700';
const str2 = '2021-10-07T12:47:12-0700';

const timeDiffInMs = new Date(str2).getTime() - new Date(str1).getTime() 
DemiPixel
  • 1,768
  • 11
  • 19
  • Just flag it as duplicate, this is not worth answering especially with no explanation when the duplicates have very complete answers. – pilchard Oct 07 '21 at 23:41
  • I'm confused what's wrong with this solution? It parses the format of date you provided correctly, and `timeDiffInMs` can contain values that represent seconds or hours. – DemiPixel Oct 07 '21 at 23:46
  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. You can find more information on how to write good answers in the help center: https://stackoverflow.com/help/how-to-answer . Good luck – nima Oct 08 '21 at 11:26