性能测试工具 jmeter 如何对提取的日期加 1

小恶魔 · 2017年12月19日 · 最后由 welles 回复于 2017年12月28日 · 3305 次阅读

jmeter 怎么实现线程 A 提取到的日期,在传递给线程 B 时实现日期加 1

A 线程提取了日期 1990-01-01,想要给线程 B 传递 1990-01-02,如何实现 +1

共收到 5 条回复 时间 点赞

${time(yyyy,)}-${time(MM,)}-${intSum(${time(dd,)},+1,)}
这样可能会在 30 号 31 号这样的日期出问题,但一般日期还可以用的

方法 1:在 sql 中处理,直接 +1
方法 2:在 BeanShell 中转成 Date 对象处理下

Mr_Peace 回复

方法二能给个案例吗,谢谢😀

niu 回复

能写一个案例吗,谢谢

beanshell:

import java.text.*;
import java.util.Date;
import java.util.Calendar;
//年:需设定的年份-1900,月:从 0 开始
Date currentTime = new Date(2017-1900,12-1,31);
Calendar c = Calendar.getInstance();
c.setTime(currentTime);
c.add(Calendar.DATE, 1);// +1 天
Date tomorrow = c.getTime();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(tomorrow);
vars.put("Date",dateString);

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册