title: JMeter - JSR223 get current time in milliseconds
body: <p>I am trying to calculate SSE traffic latency in a simple load test using the following JSR223 Sampler:</p>
  <pre><code>EventHandler eventHandler = eventText -&gt; {
    count++;
    // get the time from the server
    def result = eventText.substring(eventText.indexOf(&quot;data='&quot;) + 6, eventText.indexOf(&quot;', event&quot;)).trim() as Long;  
    def currenTime = System.currentTimeMillis();
    def diff = currenTime - result;
    list.add (diff);
    resp = resp + &quot;Time from server:&quot; + result + &quot;, JMeter time:&quot; + currenTime + &quot;, diff:&quot;+ diff +&quot;\n&quot;;  
  };
  
  SSEClient sseClient = SSEClient.builder().url(pURL).eventHandler(eventHandler).build();
        
  sseClient.start();
  
  sleep(SLEEP_TIME);
  
  sseClient.shutdown();
  </code></pre>
  <p>The time from the server (NodeJS -JavaScript) is <code>Date.now()</code> and the time on JMeter is <code>System.currentTimeMillis()</code></p>
  <p><strong>Both Server and JMeter are on the same computer.</strong></p>
  <p>It seems that the time methods are not aligned as I can see that in some cases the JMeter time is earlier than the server time:</p>
  <p><a href="https://i.stack.imgur.com/3eMpy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3eMpy.png" alt="enter image description here" /></a></p>
  <p>So I cannot trust the results...</p>
  <p>Any other methods I should use on the JavaScript side or the JMeter side?</p>