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.
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.
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.
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 integerDemo:
Reference materials:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With