0

I'm looking for a way to get something like: 10 minutes after taking the difference from a Date.now() - a date already passed.

Like this:

const test: any = new DeviceModel({...device})
const difference = new Date().getTime() - test.accessTime
const accesed_at = expect : 10 minutes.

But I'm not thinking how can I do with my difference time for minutes that have already passed the date.

JKD
  • 1,279
  • 1
  • 6
  • 26
Ming
  • 1,349
  • 4
  • 13
  • 36
  • 1
    The difference will be in milliseconds, do the math. – pilchard Jan 29 '21 at 13:35
  • If that's about formatting duration in miliseconds into some human-readable form, you may find of use [that post](https://stackoverflow.com/a/62590689/11299053). Pay attention, though, it is ***seconds***-based, so you would need to adjust slightly. – Yevhen Horbunkov Jan 29 '21 at 13:40
  • 1
    This has nothing to do with the question itself, but `new Date().getTime()` could be simplified to `Date.now()`. – 3limin4t0r Jan 29 '21 at 13:42

1 Answers1

1

Try this

const differenceInMilliSeconds = new Date().getTime() - test.accessTime; //difference in milli-seconds
const difference = differenceInMilliSeconds /(1000 * 60);

Code assume that test.accessTime is the number of milliseconds since the Unix Epoch

naveen
  • 53,448
  • 46
  • 161
  • 251