0

I have 2 modules, the first one is generating ingestion_time as shown below

Long ingestion_time = System.currentTimeMillis();

The sample output of this ingestion_time is

ingestion_time = 446453570778734

Now I have the second module in python which is generating detection_time for the same event as shown below

detection_time = time.time()

The sample output of this detection_time is

detection_time = 1524807106.92

I want to have them in the same format so that I can get latency as

latency =  detection_time - ingestion_time

Both modules are on the same system.

Please help!


Edit 1

by using

now = long(time.time())
print "detection_time  = %s "%now

I get detection_time as

detection_time  = 1524808352 

which is still not comparable with generation_time as the number of digits is different

generation_time = 1524808352170 

Answer

using below-mentioned code solved my issue

now = int(round(time.time() * 1000))
print "detection_time  = %s "%now
Amarjit Dhillon
  • 2,718
  • 3
  • 23
  • 62

2 Answers2

2

What you need is to get the time in Mili seconds.

import time
millis = int(round(time.time() * 1000))
print millis

For reuse:

import time

current_milli_time = lambda: int(round(time.time() * 1000))

Then:

>>> current_milli_time()
1378761833768

This answer has been found in here

davis
  • 1,216
  • 5
  • 14
  • 27
1

The value that you provide

ingestion_time = 446453570778734

is simply not correct (based upon System.currentTimeMillis())

All you need to do is convert the python date by multiplying by 1000

detection_time = 1524807106920 == System.currentTimeMillis()
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64