-2

I have a list of UNIX epoch times (Python), something like this:

[1526496663206, 1526507363973, 1526507363973, 1526574425012]

I want to subtract them from the current time and get the left time, for example, suppose 1526496663206 represents 2018-10-03 04:53:26. I want to subtract it from the current time and get the left time in a readable format.

I can get the current time with int(time.time()).

Now how do I subtract the list of UNIX times from it? Simply doing int(time.time()) - list[i] doesn't seem to work.

How do I do that? Is there some Python function for doing that> Thanks in advance?

crazyy_photonn
  • 161
  • 3
  • 17
  • 2
    Where is your current effort? It seems like you know that you need to find the current time, and then subtract. Both of these tasks you should be able to learn with a quick google search – user3483203 Jun 21 '18 at 21:20
  • Hi. Thanks for replying. I have edited my post to show the problem. I wanted to know if there is a module/function that does this, so that I dont have to convert the time myself and then subtract keeping in mind the days, weeks, etc. – crazyy_photonn Jun 21 '18 at 21:36
  • 1
    The time you have listed is *not* October 3rd. It's May 16th, 2018. Also, in Python, `time.time()` gives you the time in seconds, while it seems your list is in milliseconds. You'll need to account for this before any subtraction can be done – user3483203 Jun 21 '18 at 21:38
  • Ohh yes, that was simply an example. I can convert the UNIX time into a readable format, but is there any method of simply subtracting the UNIX time from the current time? Thanks! – crazyy_photonn Jun 21 '18 at 21:40

1 Answers1

2

Try this:

import time


current_time = time.time()
print(current_time)
diff = current_time - 'YOUR EPOCH TIME'
time_left = now - diff
print(time_left)

formatted_time = time.strftime('%Y-%m-%d %I:%M:%S %p', time.localtime(time_left))
print(formatted_time)
probat
  • 1,422
  • 3
  • 17
  • 33