Jmeter - 未来时间戳 [英] Jmeter - Future timestamp
问题描述
我试图在 Jmeter 中创建一个参数,给出当前时间戳 + 5 分钟.有谁知道如何做到这一点?要生成当前时间戳,我有这个: ${__time(HH:mm:ss,TIMESTAMP)}
恐怕__time() 函数没有提供足够的灵活性.您需要通过 Beanshell Sampler 或 Beanshell Pre Processor 来计算此日期值 >
相关的 Beanshell 代码看起来像
import java.text.SimpleDateFormat;导入 java.util.Calendar;导入 java.util.Date;现在日期 = 新日期();//获取当前时间日历 c = Calendar.getInstance();//获取 Java 日历实例c.setTime(现在);//将日历时间设置为现在c.add(Calendar.MINUTE, 5);//将当前时间增加 5 分钟日期 now_plus_5_minutes = c.getTime();//获取修改时间的日期值SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");//为日期创建一个格式化程序String mydate = sdf.format(now_plus_5_minutes);//将日期格式化为字符串vars.put("mydate",mydate);//将日期保存到名为mydate"的 JMeter 变量中
您可以将 mydate
值引用为
- ${mydate}
- ${__V(mydate)}
在您需要提供更新日期的地方.
希望这会有所帮助.
im trying to create a parameter in Jmeter that gives the current timestamp + 5 minutes. Does anyone know how to do this? To generate the current timestamp i have this: ${__time(HH:mm:ss,TIMESTAMP)}
I'm afraid that __time() function doesn't provide enough flexibility. You'll need to calculate this date value via Beanshell Sampler or Beanshell Pre Processor
Relevant Beanshell code will look like
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
Date now = new Date(); // get current time
Calendar c = Calendar.getInstance(); // get Java Calendar instance
c.setTime(now); // set Calendar time to now
c.add(Calendar.MINUTE, 5); // add 5 minutes to current time
Date now_plus_5_minutes = c.getTime(); // get Date value for amended time
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); // create a formatter for date
String mydate = sdf.format(now_plus_5_minutes); // format date as string
vars.put("mydate",mydate); // save date to JMeter variable named "mydate"
You'll be able to refer that mydate
value as
- ${mydate}
- ${__V(mydate)}
In the place you'll need to provide that updated date.
Hope this helps.
这篇关于Jmeter - 未来时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!