When I am trying to receive mail from gmail, I get time in this format (Mon, 12 Jun 2017 10:29:07 +0530
). I want to calculate time minus current time. How to do so?
Asked
Active
Viewed 227 times
-3

VincenzoC
- 30,117
- 12
- 90
- 112

praneet drolia
- 671
- 1
- 6
- 15
-
Possible duplicate of [How do I get the difference between two Dates in JavaScript?](https://stackoverflow.com/questions/41948/how-do-i-get-the-difference-between-two-dates-in-javascript) – Antoine C. Jun 15 '17 at 09:18
-
Your question doesn't show any research effort, nor are you clear about what output you are looking for. Show what you have tried, what you got, what you expected, etc. Also, this has nothing to do with `vue.js`. – Matt Johnson-Pint Jun 15 '17 at 20:22
2 Answers
0
var testDate = moment("Mon, 12 Jun 2017 10:29:07 +0530");
//Relative to time in human readble format
testDate.fromNow(); //3 days ago

Chirag Ravindra
- 4,760
- 1
- 24
- 35
-
How to convert this into like if less than a min then only sec . if less than an hour then only min , if less than day then only hr – praneet drolia Jun 15 '17 at 06:22
-
Have updated answer to show a human readable format of the same. Probably what you are looking for. – Chirag Ravindra Jun 15 '17 at 06:46
0
You can simply call the moment constructor with the given Date format. moment.js is smart enough to parse it for you. To get the difference you can convert it into unix based time format and subtract it.
const givenTime = moment("Mon, 12 Jun 2017 10:29:07 +0530").unix()
const currentTime = moment().unix()
//Difference in milliseconds
const diff = givenTime - currentTime

Minkesh Jain
- 1,140
- 1
- 10
- 24
-
How to convert this into like if less than a min then only sec . if less than an hour then only min , if less than day then only hr – praneet drolia Jun 15 '17 at 06:25
-
-
1Please try it yourself first :) and if you don't get the answer then post on the stack overflow again. – Minkesh Jain Jun 15 '17 at 08:16