Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jmeter - Future timestamp

Tags:

java

jmeter

im trying to create a parameter in Jmeter that gives the current timestamp + 5 minutes. Does anyone know how to do this? To generate the current timestamp i have this: ${__time(HH:mm:ss,TIMESTAMP)}

like image 600
Demoric Avatar asked Feb 18 '14 07:02

Demoric


People also ask

What is __ P in JMeter?

Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function. When using \ before a variable for a windows path for example C:\test\${test}, ensure you escape the \ otherwise JMeter will not interpret the variable, example: C:\\test\\${test}.

What is timestamp in JMeter report?

The timestamp format is used for both writing and reading files. If the format is set to "ms", and the column does not parse as a long integer, JMeter (2.9+) will try the following formats: yyyy/MM/dd HH:mm:ss.


1 Answers

I'm afraid that __time() function doesn't provide enough flexibility. You'll need to calculate this date value via Beanshell Sampler or Beanshell Pre Processor

Relevant Beanshell code will look like

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

Date now = new Date(); // get current time
Calendar c = Calendar.getInstance(); // get Java Calendar instance
c.setTime(now); // set Calendar time to now
c.add(Calendar.MINUTE, 5); // add 5 minutes to current time
Date now_plus_5_minutes = c.getTime(); // get Date value for amended time
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); // create a formatter for date       
String mydate = sdf.format(now_plus_5_minutes); // format date as string
vars.put("mydate",mydate); // save date to JMeter variable named "mydate"

You'll be able to refer that mydate value as

  • ${mydate}
  • ${__V(mydate)}

In the place you'll need to provide that updated date.

Hope this helps.

like image 131
Dmitri T Avatar answered Sep 28 '22 09:09

Dmitri T