How to get current date and time in seconds in JMeter?

Problem:

How to generate epoch timestamp in seconds in JMeter script?

Solution:

JMeter function time() generates timestamp in epoch format in millisecond i.e. 13 digits numbers like 1559815879767. Sometimes there is a requirement to pass the current timestamp in second i.e. 10 digits numbers like 1559815879. Some performance testers use BeanShell code to convert epoch timestamp (which is in milliseconds) to second. Just to recall, try to avoid the use of BeanShell or Groovy coding unless you have an alternate way.

There is a simple way to generate the timestamp in second in JMeter script. Instead of writing BeanShell or Groovy code, you can use the below statement where you want to pass the timestamp in second:

${__time(/1000,)}

Refer to the screenshot showing epoch timing in milliseconds and seconds:

JMeter Time in seconds
Figure 01: Generation of epoch time in second

How does it work?:

When you use ${__time(/1000,)} then JMeter divides the timestamp (which is in milliseconds) by 1000 and passes in the request (in seconds).

If you want to save the timestamp in a variable then use below statement:

${__time(/1000,testTimeStamp)}

where,
“testTimeStamp” is a variable which stores the value generated by time() function in seconds.


2 Responses

  1. Krishna says:

    How we can generate 16 digits timestamp i mean microseconds time stamp.

Leave a Reply

Your email address will not be published. Required fields are marked *