Max P Max P - 7 months ago 51
Python Question

Substract epoch time from

I was asked to get the value of a key from a JSON on a particular website and subtract that value with

(it's an expiration date).

I'm doing it using a
as well as a
. My problem is: The value that I'm getting is epoch time and
is not.

What's the easiest way to ( - my key(epoch value)
)? See values in screenshot below. I've tried converting from epoch to "human date" then do a subtraction with it but nope.

see both values here on top and epoch from json on the bottom

EDIT: This may not be a duplicate because it asks about processing a timestamp and wants number of seconds between that timestamp and now.

Answer Source

You did say easiest. When a timestamp is involved think of the arrow library.

>>> time_string = '2017-08-14 11:52:09.145000'
>>> import arrow
>>> time_diff =
>>> time_diff.total_seconds()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download