Python Forum
Time Difference in Epoch Microseconds then convert to human readable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Time Difference in Epoch Microseconds then convert to human readable
#5
Hi ,

Thank you all, despite all trying to help, but i couldn't understand.
I have managed to solve it myself. Hence, i will just share with whoever looking for solutions too.

from datetime import datetime, timedelta

# epoch timestamp in microseconds
arr = [
'1519649295496484 -> 1519649327106949',
'1519649400617116 -> 1519649400728112',
'1519649441795007 -> 1519649442855342',
'1519649654498861 -> 1519649655227328'
]

epoch = datetime(1970, 1, 1)

if len(arr):
    for line in arr:

        tmp = []
        dateTimes = line.split('->')

        for epochTime in dateTimes:

            cookie_microseconds_since_epoch = int(epochTime)
            cookie_datetime = epoch + timedelta(microseconds=cookie_microseconds_since_epoch)
            tmp.append(cookie_datetime)

        for index, item in enumerate(tmp):

            if len(tmp) == index + 1:
                break

            elapsedTime = tmp[index + 1] - item

            print str(item) + ' -> ' + str(tmp[index + 1]) + ' : ' + str(elapsedTime)
Output:
2018-02-26 12:48:15.496484 -> 2018-02-26 12:48:47.106949 : 0:00:31.610465 2018-02-26 12:50:00.617116 -> 2018-02-26 12:50:00.728112 : 0:00:00.110996 2018-02-26 12:50:41.795007 -> 2018-02-26 12:50:42.855342 : 0:00:01.060335 2018-02-26 12:54:14.498861 -> 2018-02-26 12:54:15.227328 : 0:00:00.728467
This solution will get a list of timestamp with native epoch timestamp.
Then split the timestamp and add to its own array with datetime format.
Perform the time difference calculation.
And finally print the output. // change the printing output if you need it differently.
Reply


Messages In This Thread
RE: Time Difference in Epoch Microseconds then convert to human readable - by firesh - Feb-27-2018, 09:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Convert UTC now() to local time to compare to a strptime() Calab 2 296 Apr-29-2024, 07:24 PM
Last Post: deanhystad
  time difference bettwenn logs enkliy 14 1,154 Nov-21-2023, 04:51 PM
Last Post: rob101
  io.UnsupportedOperation: not readable RedSkeleton007 2 18,920 Nov-06-2023, 06:32 AM
Last Post: gpurdy
  Hard time trying to figure out the difference between two strings carecavoador 2 722 Aug-16-2023, 04:53 PM
Last Post: carecavoador
  Sum up Time difference tester_V 10 2,740 Apr-06-2023, 06:54 AM
Last Post: Gribouillis
  [SOLVED] Epoch timestamp without milliseconds? Winfried 5 3,200 Jan-27-2023, 04:35 PM
Last Post: deanhystad
  Human Sorting (natsort) does not work [SOLVED] AlphaInc 2 1,211 Jul-04-2022, 10:21 AM
Last Post: AlphaInc
  How to make x-axis readable with matplotlib Mark17 7 4,037 Mar-01-2022, 04:30 PM
Last Post: DPaul
  Function global not readable by 'main' fmr300 1 1,391 Jan-16-2022, 01:18 AM
Last Post: deanhystad
  sorting alphanumeric values in a human way idiotonboarding 3 2,696 Jan-22-2021, 05:57 PM
Last Post: idiotonboarding

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020