1

I have written a bash code to run iperf3 and capture packets. Then i have extracted frame time from the .pcap file using tshark. The time is in the following format Jan 27, 2020 13:22:12.683438000 CET.

Now i want to calculate the time difference between the sent and received packets, but I dont know how do i subtract time which is in this format. Which variable type should i use so that I can perform the subtraction.

I have also used datetime library but did not get results.

Nehal
  • 17
  • 4

1 Answers1

1

check if below lines can help you

from datetime import datetime
from pytz import timezone

CET = timezone('CET')

send_time = datetime.strptime('11:18:57.925 Wed Jan 5 2019', '%H:%M:%S.%f %a %b %d %Y')
print(send_time.astimezone(CET))
difference_from_now = send_time.astimezone(CET) - datetime.now().astimezone(CET)
print(difference_from_now)

received_time = datetime.strptime('08:18:57.925 Mon Jan 20 2020', '%H:%M:%S.%f %a %b %d %Y')
print(received_time.astimezone(CET))

difference_send_received = send_time.astimezone(CET) - received_time.astimezone(CET)

print(difference_send_received)
Hietsh Kumar
  • 1,197
  • 9
  • 17
  • I want the time to be in the format Jan 27, 2020 13:22:12.683438000 CET, which has 9 digits after decimal point in seconds. How do I do that? – Nehal Jan 28 '20 at 07:57
  • @Nehal , your question is about get the difference , hope my code answers it, for different , and difference cannot come zone name, it will always be in day , min, sec , years, etc, in formatting following links can help ... http://pytz.sourceforge.net/ and https://docs.python.org/3/library/datetime.html – Hietsh Kumar Feb 01 '20 at 16:18