Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Jmeter_ print current timestamp & print offset timestamp

Shulou Source: shulou.com Published: 2022-06-03 06:02:24 10月03日 Update

A function is provided in Jmeter to print a timestamp, as shown in the following figure

Year: yyyy month: MM Day: dd

Hour: HH minute: mm second: ss

As for the format of timestamps, you can freely combine and define them. Here I write yyyy-MM-dd HH:mm:ss like this.

The generated function looks like this: ${_ _ time (yyyy-MM-dd HH:mm:ss,)}

Now write this function to the next interface

Execute, check the result tree, you can see that the current time is printed out in the result.

This function is suitable for some APIs that need to enter time parameters, and can be used to obtain the current time in real time. If the time parameter is written dead, the interface will report an error after a period of time.

Let's talk about how the time offset prints.

Speaking of time offset, that is to say, I not only want to print the current time, I also want to print tomorrow, background, or even next year's time, so how are we going to deal with it? You need to use BeanShell Sampler here.

Pass variables in Parameters, execute and view the result tree, and find that an one-year timestamp has been successfully printed.

Attached: the code of beanshell print time

Import java.text.SimpleDateFormat

Import java.util.Calendar

Import java.util.Date

Try {

Date date = new Date (); / / get the current time

SimpleDateFormat sf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss")

String nowDate = sf.format (date)

Calendar cal = Calendar.getInstance ()

Cal.setTime (sf.parse (nowDate))

Cal.add (Calendar.DAY_OF_YEAR,+0)

String orderDate = sf.format (cal.getTime ())

Cal.add (Calendar.DAY_OF_YEAR,+365)

String senderDate = sf.format (cal.getTime ())

Vars.put ("orderDate", orderDate)

Vars.put ("senderDate", senderDate)

}

Catch (Exception e) {

}

Tags: Time function interface offset parameter fruit tree success freedom code time variable background real-time that is format result span will report process Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Information Xiaomi Shulou Tech Info Shulou Technology