K.Rice K.Rice - 9 days ago 5
TypeScript Question

How to substract current utc time from php iso utc?

I want to get current time in

UTC
, substract it from
ISO UTC string
which I'm getting from backend in the following format:
2016-11-29T17:53:29+0000
(ISO 8601 date, i guess?) and get an answer in milliseconds.

What is the shortest way to do it in javascript? I'm using angular 2 and typescript frontend.

Answer

You can get the current time using:

var now = Date.now()

And convert the string to a milliseconds timestamp using:

var ts = (new Date('2016-11-29T17:53:29+0000')).getTime()

And then subtract the values:

var diff = ts - now