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.
Asked
Active
Viewed 3.0k times
10
-
below link might be helpful http://stackoverflow.com/questions/27043029/jmeter-get-current-date-and-time – Snehal Patel Feb 21 '17 at 10:10
-
@SnehalPatel : checked that already. that is useful when somebody wants it in a specific format like DD/MM/YY or DD-MM-YY. – vishal Feb 21 '17 at 10:14
-
this link could help - https://stackoverflow.com/a/62231892/4398100 – Anshul Singhal Jun 06 '20 at 13:09
3 Answers
18
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:
Reference materials:

Dmitri T
- 159,985
- 5
- 83
- 133
13
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.

Naveen Kumar R B
- 6,248
- 5
- 32
- 65
-
yeah Naveen..checked that. but my application supports date in only seconds. i just wanted to know about any other function or method which can change it to seconds while running the test. – vishal Feb 21 '17 at 10:21
0
Use __timeShift() and __jexl3() functions combination
with __timeShift() you will get the date in past/future in milliseconds since start of the Unix epoch see screenshot here
and with __jexl3() you can simply divide the resulting value by 1000 to get the value in seconds

Wodem
- 1
- 1