K.Rice K.Rice - 1 month ago 11
TypeScript Question

How to substract current utc time from php iso utc?

I want to get current time in

, substract it from
ISO UTC string
which I'm getting from backend in the following format:
(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.


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