Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Jmeter_ print current timestamp & print offset timestamp

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

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) {

}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report