-3

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?

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 Answers2

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
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