10

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.

vishal
  • 247
  • 1
  • 2
  • 9

3 Answers3

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:

JMeter time javascript functions

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

see screenshot here

Wodem
  • 1
  • 1