title: Get start time, end time and test duration of JMeter load test
body: <p>I need to capture StartTime(Format:2021-04-28T12:09:09.000009), EndTime(Format:2021-04-28T12:09:09.000009) and test duration(milliseconds) of a JMeterLoad test.
  I planning to capture StartTime(Format:2021-04-28T12:09:09.000009) in SetupThreadGroup in Jsr223Sampler and EndTime(Format:2021-04-28T12:09:09.000009) &amp; duration in tearDownThreadGroup using below code.</p>
  <p>---SetupThread</p>
  <pre><code>def now = new Date()
  def starttime = now.format(&quot;yyyy-MM-dd'T'HH:mm:ss.ssssss&quot;, TimeZone.getTimeZone('UTC'))
  vars.put(&quot;StartTime&quot;, starttime)
  </code></pre>
  <p>--- TearDownThreadGroup</p>
  <pre><code>def now = new Date()
  def endtime = now.format(&quot;yyyy-MM-dd'T'HH:mm:ss.ssssss&quot;, TimeZone.getTimeZone('UTC'))
  vars.put(&quot;EndTime&quot;, endtime)
  def diff = vars.get(&quot;StartTime&quot;)-endtime
  </code></pre>
  <p>Getting below error</p>
  <pre><code>2021-04-28 18:17:11,475 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script GetEndTime_Duration, message: javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method minus() on null object
  javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method minus() on null object
  </code></pre>