1

Whenever I run ${__timeShift(HH:mm,,PT30M,,)} from the Function Helper, it gives me the time in CST (my local timezone)

I'm having trouble figuring out how to use timeShift to evaluate the HH:mm value without automatically converting it to CST time. Is there a simple way to do this, or will I need to use to use a JSR223 process to calculate the UTC value and vars.put it as a variable?

The ultimate goal is to use this value in an HTTP Sampler.

I've tried various combinations of parameters from the https://www.perfmatrix.com/jmeter-timestamp/

Also tried some basic time conversions in a JSR223 process. I am extremely new to both Java and JMeter though, so I haven't had much success.

2 Answers2

2

You can achieve this using the following scary __groovy() function:

${__groovy(java.time.ZonedDateTime.now(java.time.ZoneId.of("UTC")).plusMinutes(30).format(java.time.format.DateTimeFormatter.ofPattern("HH:mm")),)}

More information: The Groovy Templates Cheat Sheet for JMeter

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • I do not have experience with groovy; therefore, I can not comment on the groovy part. This comment is about introducing the modern date-rime API, `java.time` API. Good job! A bit cleaner code would be using `java.time.OffsetDateTime.now(java.time.ZoneOffset.UTC)`. – Arvind Kumar Avinash Nov 24 '22 at 10:56
0

Answer was to set a default time zone:

TimeZone.setDefault(TimeZone.getTimeZone('UTC'))

def theTime = ${__timeShift("HH:mm",,PT30M,,)}