Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jmeter- How to get current date and time in seconds

Tags:

jmeter

i want to calculate current time in seconds and use it as a parameter in my jmeter test plan. By default the time is in milliseconds. Can somebody help me please.

like image 865
vishal Avatar asked Feb 21 '17 10:02

vishal


People also ask

How do I parameterize a timestamp in JMeter?

If you want to pass the current timestamp (in epoch format) in the request then you can directly use ${__time()} else you can use the above-mentioned argument and generate the value in desired time format. In case you want to save the value in a variable then add a variable name next to the format separated by a comma.

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.


2 Answers

You can use __time() function, by default it returns current time in milliseconds since beginning of Unix epoch

If you need this time in "seconds" precision - just divide it by 1000 using i.e. __javaScript() function

So:

  • ${__time(,)} will return current time in milliseconds
  • ${__javaScript(${__time(,)} / 1000,)} - will return current time in seconds
  • ${__javaScript(Math.round(${__time(,)} / 1000),)} - will round up the current time in seconds to the nearest integer

Demo:

JMeter time javascript functions

Reference materials:

  • JMeter Functions and Variables
  • SimpleDateFormat patterns
  • How to Use JMeter Functions - Part III
like image 141
Dmitri T Avatar answered Oct 15 '22 21:10

Dmitri T


Use __time function with format string as /1000.

 ${__time(/1000,)} - to get time in seconds

From JMeter DOCs:

For example, "/1000" returns the current time in seconds since the epoch.

like image 30
Naveen Kumar R B Avatar answered Oct 15 '22 23:10

Naveen Kumar R B